[R] iterating through for loop

Petr PIKAL petr.pikal at precheza.cz
Fri Feb 3 13:51:47 CET 2012


Hi

> [R] iterating through for loop
> 
> how to iterate two elements each through for loop?
> e.g. x<-c(1,2,4,7,34,6)
> y<-c(3,5,6,9,34,7)
> 
> for(z in x){
> print(paste(z,y))  }
> 
> 
> i want both element of vector iterate serially with same position

Not sure what the result shall be. but

paste(x,y)

and

do.call(paste, lapply(expand.grid(x,y), paste))

is what comes to my mind.

If you want something else please follow rules suggested in posting guide.

Regards
Petr


> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/iterating-
> through-for-loop-tp4354101p4354101.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.



More information about the R-help mailing list