[R] elegant way to create a sequence with the 'rep' bulit-in function
Kathryn Lord
kathryn.lord2000 at gmail.com
Sat May 23 16:55:59 CEST 2015
Dear R users,
I'd like to create a sequence/vector, for example,
1 1 2 2 3 3 1 1 2 2 3 3 1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 5 4 4 4
4 5 5 5 5 4 4 4 4 5 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 6 6 6 7 7 7 8 8 8 9
9 9
So I did like this below.
a <- 4
b <- 3
c <- 2
grp <- c( rep(1:b, each=c, times=a), rep(1:c, each=a, times=b)+b, rep(1:a,
each=b, times=c)+b+c )
I wonder if there is a more elegant way to do this?
Any suggestions? Thank you!
Best wishes
Kathie
[[alternative HTML version deleted]]
More information about the R-help
mailing list