Hi all,
I am try to do a loop  on a data .such as:

X<-data.frame(name=c(1:9),SN=c(1,1,1,2,2,2,3,3,3),EW=rep(1:3,3))
X
  name SN EW
1    1  1  1
2    2  1  2
3    3  1  3
4    4  2  1
5    5  2  2
6    6  2  3
7    7  3  1
8    8  3  2
9    9  3  3


out<-list()
for ( i in 1:3) {out[[i]]<-subset( X,X$SN==1&EW==i) } ##this expression can have the subset of EW=1 (and EW=2 EW=3) when SN=1
out
[[1]]
  name SN EW
1    1  1  1

[[2]]
  name SN EW
2    2  1  2

[[3]]
  name SN EW
3    3  1  3



Question: What can I do if I want to have the all subset at once when SN=1:3 ? How to write the loop?

thank you very much!

----hanwenheng

______________________________________________
R-help@r-project.org 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.

Reply via email to