set.seed(123)
dataset <- data.frame(ID = 1:10,
height_1 = rnorm(10,0,1),
height_2 = rnorm(10,0,1),
common_fam = rnorm(10,0,1),
weight_1 = rnorm(10,0,1),
weight_2 = rnorm(10,0,1),
common2_fam2 = rnorm(10,0,1))
So, the above is a reproducible minimum data example. my real data is more complicated.
data3 <- dataset %>%
pivot_longer(-c('ID', ends_with("fam") | ends_with("fam2")),
names_to = "fID",
values_to = "value",
names_sep = "_")
What I intended is that
data3 contains columns such as:
"ID", "common_fam", "common2_fam2",
"fID" (it contains values either 1 or 2),
"height" and "weight"