I was looking at similar questions but I couldn't find a case similar to mine. I have a data frame that for each subject, has multiple observations per condition. It looks like this:
subject <- c(rep("S1",4), rep("S2",4))
condition <- rep(c(rep("a",2), rep("b",2)),2)
value <- c(1:8)
df <- data.frame(subject,condition,value)
df
subject condition value
S1 a 1
S1 a 2
S1 b 3
S1 b 4
S2 a 5
S2 a 6
S2 b 7
S2 b 8
I would like to reshape it to look like this:
subject condition.a condition.b
S1 1 3
S1 2 4
S2 5 7
S2 6 8
I have tried reshape and cast, but they give me an error message because there are multiple observations per subject and condition. Does anyone have suggestions on how they would do this?
Thanks!