d <- c('a', 'b', 'c')
n <- c(1, 2, 5)
I would like to produce output:
res <- c('a', 'b', 'b', 'c', 'c', 'c', 'c', 'c')
Is there a function which can use d
and n
to produce such a result?
CodePudding user response:
We could use rep()
:
rep(d, n)
[1] "a" "b" "b" "c" "c" "c" "c" "c"