I am trying to take the following small sample of data:
IndID J2015 E2015 Area
1 10 5 DC
2 15 7 DC
3 20 10 DC
Then use reshape
or reshape2
to transform it into the following format:
Area 1_J2015 1_E2015 2_J2015 2_E2015 3_J2015 3_E2015
DC 10 5 15 7 20 10
I will be doing this over a few million rows of data, however I cannot figure out the correct formula to perform this, part of me believes this needs to be done in two or more steps.
I have tried various formats of the dcast
function in the reshape
package:
df <- dcast(AreaID + J2015 + E2015 ~ IndID, data = data)
Thank you in advance.