I am trying to get newdf
from ``olddf. Basically, I want to duplicate and stack columns
Aand
Bto allow for columns
Cand
D```` to be stacked in a single column. Sorry for the bad explanation, essentially, I am stacking C
and D
into a single column and need to repeat A
and B
to account for the repetitions, thank you.
olddf <- data.frame('A' = c('Z1','Z2','Z3'),
'B' = c(100, 200, 500),
'C' = c(90, 50, 60),
'D' = c(NA, 50, NA))
newdf <- data.frame('A' = c('Z1','Z2','Z3','Z1','Z2','Z3'),
'B' = c(100, 200, 500, 100, 200, 500),
'CD' = c(90, 50, 60, NA, 50, NA))