Frederico,
This is not exactly what you're after, but perhaps it will help. In this
example I fit a cluster analysis to the data, then I "cut the tree" at a
height of 3 (you would do this with your data at a height of 40). It's
not a perfect solution, but it might be good enough, depending on the
spatial distribution of your points.
# example data frame with x and y (on the same scale)
df <- data.frame(x = rnorm(100), y = rnorm(100))
# cluster analysis
tree <- hclust(dist(df[, c("x", "y")], method="euclidean"),
method="complete")
# define groups as those that are at least 3 units apart
df$group <- cutree(tree, h=3)
# plot the data, using color and symbol to identify group membership
eqscplot(df$x, df$y, col=df$group, pch=df$group)
Jean
"Frederico Mestre" <[email protected]> wrote on 07/30/2012
07:29:00 AM:
>
> Hello:
>
> What I want to do is quite simple, but I can't find a way.
>
> I have a data frame with several points (x and y coords). I want to add
> another column with cluster membership. For example aggregate all the
points
> that stand within a distance of 40 from each other.
>
> I've tried using "nncluster" from the package nnclust, but the results
are
> not correct, for some reason (probably my mistake).
>
> This is what I did:
>
> x <- nncluster(as.matrix(dframe[,1:2]), threshold=35, fill = 1, maxclust
=
> NULL, give.up = 500,verbose=FALSE,start=NULL)#avaliar as clusters
>
> Thanks,
>
> Frederico
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.