I want to repeat a vector N times but element-wise, not the whole vector.
For instance, I have:
v <- c('a', 'b')
Say I want to repeat n times:
n <- 3
I want:
vfill <- c(rep(v[1], n), rep(v[2], n))
print(vfill)
[1] "a" "a" "a" "b" "b" "b"
My best solution to date:
ffillv <- function(i) rep(v[i], n)
c(sapply(seq_len(length(v)), ffillv))
I am interested in fast & scalable solutions, for instance using rbind, plyr, etc.