I'd appreciate help on the following data-wrangling task. I have a data frame that looks like this:
df <- data.frame(var1=c('a', 'b', 'c'), var2=c('d', 'e', 'f'), var3=c('h', 'j', 'k'))
I want to replicate each row of data with var1 and var2 fixed number of times, let's say 3 times, but not var3. In place of missing values in var3 I want to have 0s.
In the end, I would like to have this:
df.expanded
var1 var2 var3
1 a d h
2 a d 0
3 a d 0
4 b e j
5 b e 0
6 b e 0
7 c f k
8 c f 0
9 c f 0