I have a bigger dataset, but I made this smaller one for the purpose of this example. My dataset looks like this
df <- data.frame(ID = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3),
APPT_ID = c(11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14),
Variable = c(letters[1:3], letters[1:3], letters[1:3], letters[1:3]),
Value = c(41:52))
The first two columns (ID and APPT_ID) are identifiers for each observation, so I would like to maintain those as columns, while transposing the second two columns (variable and value) such that each of the variables is its own column showing its value. I would like there to be only one observation row for every unique combination of ID and APPT_ID.
I'd like my output dataset to look like this:
df2 <- data.frame(ID = c(1, 1, 2, 3), APPT_ID = c(11, 12, 13, 14),
a = c(41, 44, 47, 50), b = c(42, 45, 48, 51),
c = c(43, 46, 49, 52) )
Whats the best why to do this?