[R] creating a closed loop for a list

djrwicks djrwicks at gmail.com
Wed Dec 21 12:56:41 CET 2011


Given the following, how to I get x[i+1] to not return an NA result when it
gets to the end of list x by looping back to the start of the list
i.e should return: 0 0 2 2 2 2?

> x<-c(2,0,0,2,2,2)
> i<-1:length(x)
> x[i]
[1] 2 0 0 2 2 2
> x[i+1]
[1]  0  0  2  2  2 NA
 
can i be described using a loop that says go back to the beginning of list
x?

--
View this message in context: http://r.789695.n4.nabble.com/creating-a-closed-loop-for-a-list-tp4221333p4221333.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list