Skip to content
Prev 332977 / 398503 Next

repeating values in an index two by two

Here's a rather extreme solution:

 foo<-rep(1:6,each=2)
Rgames> foo
 [1] 1 1 2 2 3 3 4 4 5 5 6 6

Rgames> foo[rep(c(1,3,2,4),3)+rep(c(0,4,8),each=4)]
 [1] 1 2 1 2 3 4 3 4 5 6 5 6

In the general case, then, it would be something like

foo<- rep(1:N, each = 2)  # foo is of length(2*N)

foo[rep(c(1,3,2,4),2*N/4 + rep( seq(0, 3*N/4,by=4),each=4)]

Note that the refolding requires the sequence to have length a multiple of
4.




Patrick Burns wrote

            

            
--
View this message in context: http://r.789695.n4.nabble.com/repeating-values-in-an-index-two-by-two-tp4680210p4680234.html
Sent from the R help mailing list archive at Nabble.com.