This probably has incredibly simple answer, but I've been working on this for hours and I still can't figure it out. All I want to do is take a data frame with two columns (BEFORE table) and alter it so that each unique value in the first column becomes the name of each new column and the second column values fill in below their respective column name (AFTER table).
BEFORE
ID age
N1 7
N1 8
N2 5
N3 9
N3 4
N3 9
AFTER
N1 N2 N3
7 5 9
8 NA 4
NA NA 9
I've tried the melt()
and cast()
functions in the package reshape2, but they don't seem to do what I want. Any suggestions? Thank you in advance!