ravi.raghava1
2013-Jul-31 07:46 UTC
[R] Using If loop in R how to extract even and odd ids
I have 500 ids ; i want to take out even and odd ids separately and store it another data files. How can it be done in R by using *If and for loop* ?? -- View this message in context: http://r.789695.n4.nabble.com/Using-If-loop-in-R-how-to-extract-even-and-odd-ids-tp4672707.html Sent from the R help mailing list archive at Nabble.com.
Hello, Who told you you need a loop or an if? even <- function(x) x %% 2 == 0 x <- 1:50 idx <- even(x) x[idx] Hope this helps, Rui Barradas Em 31-07-2013 08:46, ravi.raghava1 escreveu:> I have 500 ids ; i want to take out even and odd ids separately and store it > another data files. > How can it be done in R by using *If and for loop* ?? > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Using-If-loop-in-R-how-to-extract-even-and-odd-ids-tp4672707.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >
Hi, May be this helps: set.seed(24) dat1<- data.frame(ID=1:500,value=rnorm(500)) res<- split(dat1,dat1$ID%%2) A.K. ----- Original Message ----- From: ravi.raghava1 <ravi.raghava at classle.co.in> To: r-help at r-project.org Cc: Sent: Wednesday, July 31, 2013 3:46 AM Subject: [R] Using If loop in R how to extract even and odd ids I have 500 ids ; i want to take out even and odd ids separately and store it another data files. How can it be done in R by using *If and for loop* ?? -- View this message in context: http://r.789695.n4.nabble.com/Using-If-loop-in-R-how-to-extract-even-and-odd-ids-tp4672707.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at 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.