how to get a series of results by "loop"
Try this:
set.seed(1)
r <- .1
n <- 5
test <- data.frame(sp = paste("sp", 1:n, sep = ""), x= rnorm(n), y = rnorm(n))
r <- 1 # radius
f <- function(i) cbind(orig = test[i,1], subset(test, (x - x[i])^2 +
(y - y[i])^2 < r^2))
do.call("rbind", lapply(1:n, f))
On 5/26/06, zhang jian <jzhang1982 at gmail.com> wrote:
I donot know how to do it remainly.
Perhaps my question is not clear.
For example,
test=data.frame(sp=paste(c("sp"),1:100,sep=""),x=rnorm(100),y=rnorm(100))
# I want to get the data in the circle of radius = 1 in every point, and I
want to add a sign (e.g. sp1,sp2....) in order that I can distinguish
different groups
# if I want to choose a point, I can do it like this
r = 1 # radius
attach(test)
point100=test[(x-x[100])^2+(y-y[100])^2<=r^2,]
result100=data.frame
(note=paste(c("p"),rep(100,length(point100$sp)),sep=""),point100)
detach(test)
But if I want to do all points in "test", I donot know how to do it. I try
to do it by using "for", but it doesnot work.
Can you give me some advices?
thanks!
jian zhang
[[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html