converting a dataset from a long to wide format.

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

Thanks for your first post! Can you post a reproducible example? Show us some of your data and manually make an example of what you want the result to look like after making wide.

1 Like

Thanks Steph, i included an image of what the dataset looks like now and what i want to make it look like after making it wide

Screenshots are not reproducible examples. Please look at the linked guides. They help people help you.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.