I need to generate a vector of the following format using R:
1:10, 1:10, 11:20, 11:20, ... 121:130, 121:130
Is there an easier way than creating 12 vectors and then repeating each one twice?
I need to generate a vector of the following format using R:
1:10, 1:10, 11:20, 11:20, ... 121:130, 121:130
Is there an easier way than creating 12 vectors and then repeating each one twice?
Is this what you want?
unlist(lapply(rep(seq(1, 121, by=10), each=2), function(x) seq(x, x+9)))
I think this will do you.
x <- ((0:12)*10)+1
y <- x + 9
repeatVectors <- function(x,y){
rep(seq(x,y),2)
}
z <- mapply(repeatVectors, x,y)
z <- as.vector(z)
Alternatively, you could use a combination of rep
and outer
, such as:
c(outer(1:10,rep(0:12,each=2),function(x,y)10*y+x))