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
Post a Comment