In R, I have data where each person has multiple session dates, and the scores on some tests, but this is all in one row. I would like to change it so I have multiple rows with the persons info, but only one of the session dates and corresponding test scores, and do this for every person. Also, each person may have completed different number of sessions.
Ex:
ID Name Session1Date Score Score Session2Date Score Score
23 sjfd 20150904 2 3 20150908 5 7
28 addf 20150905 3 4 20150910 6 8
To:
ID Name SessionDate Score Score
23 sjfd 20150904 2 3
23 sjfd 20150908 5 7
28 addf 20150905 3 4
28 addf 20150910 6 8
You can use
meltfrom the devel version ofdata.tableie.v1.9.5. It can take multiple 'measure' columns as a list. Instructions to install arehereOr using
reshapefrombase R, we can specify thedirectionas 'long' andvaryingas alistof column indexIf needed, the
rownamescan be changedUpdate
If the columns follow a specific order i.e. 3rd grouped with 6th, 4th with 7th, 5th with 8th, we can create a
matrixof column index and thensplitto get thelistfor thevaryingargument inreshape.