How can I transform a dataset in "wide" format that has sets of columns of different types, into "long" format, as in the example bellow? Preferably using tidyr (and dplyr, etc) or some equally simple syntax.
d_wide <- data.frame(
pair_id=1:3,
name_wife=c('Ana','Maria','Kely'),blood_type_wife=c('A','B','C'), age_wife=c(34,21,55),
name_husb=c('Bob','Peter','John'),blood_type_husb=c('B','O','A'), age_husb=c(31,24,60)
)
d_long <- data.frame(
pair_id=c(1,1,2,2,3,3),
role=c('wife','husb','wife','husb','wife','husb'),
name=c('Ana','Bob','Maria','Peter','Kely','John'),
blood=c('A','B','B','O','C','A'),
age=c(34,31,21,24,55,60)
)
OBS: other related SO questions, such as this, involve sets of columns of the same type, all numeric. Then the answer in those involves gathering (melting) the data into a "ultra-long" format and spreading back to the desired long format. This would not work here, as the variables are of different types, so they can´t be represented by the same "value" column in the ultra-long format.