I understand pivot_longer
but I dont know how to do it chunks, I have entered input & expected output in reproducible dataframe for better understanding
ip= data.frame(
stringsAsFactors = FALSE,
Question = c(1L, 2L),
name_1 = c("abc", "abc2"),
age_1 = c(12L, 34L),
name_2 = c("xyz", "xyz2"),
age_2 = c(34L, 45L)
)
op=data.frame(
stringsAsFactors = FALSE,
question = c(1L, 1L, 2L, 2L),
Member = c(1L, 2L, 1L, 2L),
Name = c("abc", "xyz", "abc2", "xyz2"),
age = c(12L, 34L, 34L, 45L)
)
Ideally there are 13 demo inputs for each 20 members, so a programmatic way rather than hard coding would be preferred solution.