I am very new to R and not sure on the correct code to use to complete this action.
I need to convert this dataset from long to wide format. The columns (Responseld, Duration, interest and def) were measured twice in the wave column (1 and 2). so i want to create two columns for each Responseld, Duration, interest and def that represent the scores taken in wave 1 and wave 2.
This is the code i was trying to use.
pivot_wider(data, names_from = "name",
values_from = "value")
This is an example of my data.
structure(list(id = c("R_00A0gwBx63DxWmt", "R_00A0gwBx63DxWmt",
"R_0ciHrETdEv7DlOp", "R_0ciHrETdEv7DlOp", "R_0DRBQNJIiHypFWV",
"R_0DRBQNJIiHypFWV"), wave = c(1, 2, 1, 2, 1, 2), ResponseId = c("R_00A0gwBx63DxWmt",
"R_3HYwAtNSInhNWIj", "R_0ciHrETdEv7DlOp", "R_2uxsAbFPu3Ewip7",
"R_0DRBQNJIiHypFWV", "R_3j6yWC4gn1fOeBd"), Duration = c(223,
159, 289, 183, 129, 102), interest = c(4, 3, 4, 3, 7, 7), def = c(7,
4, 4, 4, 4, 4)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
The top image is the untouched dataset and the image below it is what i am trying to change my data into