I am trying to reshape my data to wide, trying to prep the data frame to a within-subject analysis. It is currently suitable for a between-subject analysis. The most helpful answer I found so far was: Using the reshape function in R with multiple matching rows
My data looks like this:
SubjID ITEM SubjGroup Strength Timing Accuracy RT
1 dance 1 1 200 1 1234
1 dance 1 2 200 0 430
1 dance 1 1 400 1 450
1 dance 1 2 400 1 200
2 dance 2 1 200 0 300
2 dance 2 2 200 0 755
2 dance 2 1 400 1 550
2 dance 2 2 400 1 520
What I need is to basically remove the Strength column and replace it with an additional RT column, so that RT1 refers to the Value I got under Strength1 and RT2 refers to the value I got under Strength2 and do the same for accuracy. Each item is repeated 4x for each Subject (under two different combinations of Strength+timing), which means that by the end of the reshaping, there will be 2 rows for each verb and for each subject instead of 4 per item and per subject. Like this :
SubjID ITEM SubjGroup Timing RT1 RT2
1 dance 1 200 1234 430
1 dance 1 400 450 200
2 dance 2 200 300 755
2 dance 2 400 550 520
While either deleting the Accuracy column (if it makes things easier) or adding a second one.
I tried a simple reshape formula (the same as the one posted by OP in the link above) and it somehow worked on a similar dataframe with the same table headings but there was only one subject ID : reshape(datafr, idvar = c("ï..Subject", "Timing", "Group", "ITEM"), timevar= "TMS", direction = "wide")
When I tried it with the data above it did create the right column but it was empty and I got the warning message. I also tried with Pivot but it did not work.
Thanks!