Is there a way I can get newdf
from olddf
, by creating a new variable for the column name and a variable for the result? 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),
'var' = c('C', 'C', 'C', 'D', 'D', 'D'),
'res' = c(90, 50, 60, NA, 50, NA))