r - Create a vector using rep() and seq() -


how create vector sequence of:

2 3 4 5 6 7 8 3 4 5 6 7 8 4 5 6 7 8 5 6 7 8 6 7 8 7 8 

i tried use:

2:8+rep(0:6,each=6) 

but result is:

2 3 4 5 6 7 8 3 4 5 6 7 8 9 4 5 6 7 8 9 10 .... 12 13 14 

please help. thanks.

you this:

library(purr) unlist(map(2:7, ~.x:8))  # [1] 2 3 4 5 6 7 8 3 4 5 6 7 8 4 5 6 7 8 5 6 7 8 6 7 8 7 8 

and little function in base r:

funky_vec <- function(from,to){unlist(sapply(from:(to-1),`:`,to))} funky_vec(2,8) # [1] 2 3 4 5 6 7 8 3 4 5 6 7 8 4 5 6 7 8 5 6 7 8 6 7 8 7 8 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -