I would like to turn this dataframe from wide to long. I know that there are some similar posts about the topic, for instance I have tried all the options from this one:
Reshaping wide to long with multiple values columns
but I keep having the same error message: Warning in value[[jj]][ri] <- if (is.factor(xij)) as.vector(xij) else xij : number of items to replace is not a multiple of replacement length
I don't know how I can fix this, any help? Thank you very much
df3<-structure(list(id = structure(c("SA01", "SA02", "SA03", "SA04",
"SA05", "SA06", "SA07", "SA08", "SA09", "SA10", "SA11", "SA12",
"SA13", "SA14", "SA15", "SA16", "SA17", "SA18", "SA19", "SA20"
), label = "Code of PrevenGo", format.spss = "A5", display_width = 12L),
group = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Metab",
"SA", "SC"), class = "factor"), age_1 = structure(c(11.47,
9.6, 6.36, 10.72, 11.32, 11.66, 11.67, 7.29, 11.85, 10.72,
10, 9, 11.91, 10.8, 11.1, 10.61, 11.11, 7.6, 9.24, 10.72), format.spss = "F16.2", display_width = 15L),
whz_1 = structure(c(-0.43, 1.55, -0.19, 0.94, 0.87, 0.32,
1.97, 1.54, 1.68, 1.79, 1.25, 0.78, -0.86, 1.75, 0.28, 2.02,
3.14, 1.67, 1.03, 2.21), label = "Weight/Length", format.spss = "F5.2", display_width = 11L),
age_2 = structure(c(12.02739726, 10.07945205, 6.890410959,
11.28219178, 11.86575342, NA, 12.21369863, 7.805479452, NA,
11.31780822, 9.561643836, 9.561643836, 12.46575342, 11.35616438,
11.66027397, 11.14520548, 11.64383562, NA, NA, 11.19726027
), label = "6m Age", format.spss = "F16.2", display_width = 15L),
whz_2 = structure(c(-0.82, 1.62, -0.2, 1.08, 0.76, NA, 1.76,
1.45, NA, 1.6, 1.07, 0.79, -0.92, 1.83, 0.48, 2.21, 3.22,
NA, NA, 2.09), label = "6m Weight/Length", format.spss = "F5.2", display_width = 11L)), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
dfstack<-reshape(df3, idvar = "id", varying = list(c(3,5),c(4,6)), v.names = c("age", "whz"), direction = "long")