how to get a series of results by "loop"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

how to get a series of results by "loop"

Zhang Jian
I want to get a series of results by "loop".
For example, when i = 1, get a data frame "r1"; when i = 2, get a data frame
"r2" ...... And the result include all the data frames.
But I donot know how to get a series of data frames.
Thanks!

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: how to get a series of results by "loop"

Gabor Grothendieck
See 7.21 of the R FAQ

http://www.ugcs.caltech.edu/manuals/math/R-2.2.1-FAQ/R-FAQ_71.html

On 5/25/06, zhang jian <[hidden email]> wrote:

> I want to get a series of results by "loop".
> For example, when i = 1, get a data frame "r1"; when i = 2, get a data frame
> "r2" ...... And the result include all the data frames.
> But I donot know how to get a series of data frames.
> Thanks!
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: how to get a series of results by "loop"

Zhang Jian
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]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: how to get a series of results by "loop"

Gabor Grothendieck
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 <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html