df <- tibble(
uid = c("x1","x2","x3"),
v13y1 = c(1,3,5),
v13y1i = c(0,1,0),
v13y1ii = c(1,0,0),
v13y1iii = c(0,1,1),
v13y1iv = c(0,2,0),
v13y1v = c(1,3,0),
v13y2 = c(2,3,2),
v13y2i = c(0,1,0),
v13y2ii = c(1,0,0),
v13y2iii = c(0,1,1),
v13y2iv = c(0,2,0),
v13y2v = c(1,3,0)
)
I would like to split and rename the columns based on multiple column names. Desired output data frame should have the names of the columns as follows:
df_new <- tibble(uid = c("x1","x1", "x2","x2", "x3","x3"),
v13y = c(1,2,3,3,5,2),
n1 = c(0,0,1,1,0,0),
n2 = c(1,1,0,0,0,0),
n3 = c(0,0,1,1,1,1),
n4 = c(0,0,2,2,0,0),
n5 = c(1,1,3,3,0,0))