I have a data frame dd and a vector vec. I want to multiply the dataframe as many times as is the length of the vector. Also, I want to add this vector element as a new column to the dataframe.
# Dummy data
dd<- data.frame(id = c(1,2,3,4,5))
vec <- c("a", "b", "d")
Desired output:
id vec
1 1 a
2 2 a
3 3 a
4 4 a
5 5 a
6 1 b
7 2 b
8 3 b
9 4 b
10 5 b
11 1 d
12 2 d
13 3 d
14 4 d
15 5 d
Originally, I would get the length(vec), use rep(vec, each = length(vec)) and then add this column to rbind(dd, dd,dd). But, if need to replicate dd twenty times, how to do this in a smarter way?