I am quite new to R and I am having some trouble trying to convert my df from wide to long. At the moment it looks like below:
| ppt_num | w.1.rt | w.1.vrt | w.2.rt | w.2.vrt | n.1.rt | n.1.vrt | n.2.rt | n.2.vrt |
|---|---|---|---|---|---|---|---|---|
| 1 | 0.90 | 2.00 | 1.25 | 2.05 | 1.01 | 1.85 | 2.06 | 1.76 |
| 2 | 1.02 | 2.04 | 3.02 | 2.45 | 1.07 | 1.95 | 2.54 | 1.60 |
There are two experimental conditions and two difficulty levels. For the experimental conditions "w" stands for want priming and "n" stands for need priming. For the difficulty level 1 refers to difficult trials and 2 refers to easy trials. Finally, rt (reaction time) and vrt (variance of reaction time) are my measurements of interest. I am trying to reshape my data so that it looks like below:
| ppt_num | type | difficulty | rt | vrt |
|---|---|---|---|---|
| 1 | w | 1 | 0.90 | 2.00 |
| 1 | w | 2 | 1.25 | 2.05 |
| 1 | n | 1 | 1.01 | 1.85 |
| 2 | n | 2 | 2.06 | 1.76 |
| 2 | w | 1 | 1.02 | 2.04 |
| 2 | w | 2 | 3.02 | 2.45 |
| 2 | n | 1 | 1.07 | 1.95 |
| 2 | n | 2 | 2.54 | 1.60 |
So far I have tried using melt() but this does not produce the desired outcome.
new_df <- melt(df, id.vars = c("ppt_num"))
Any advice on the approach to take here would be very much appreciated.