A dataset has found its way to me that is set up with each sample occupying a number of a rows, each of those rows for a certain variable (Type
) that looks like this:
ID Lat Lon Type %
01 yy1 xx1 A 30
01 yy1 xx1 B 45
01 yy1 xx1 C 25
02 yy2 xx2 A 10
02 yy2 xx2 B 60
02 yy2 xx2 C 30
03 yy3 xx3 A 15
...
I need to rearrange it like this, creating new columns for each variable in column Type
and dropping out the %
column, using it's entries to populate the new columns:
ID Lat Lon A B C
01 yy1 xx1 30 45 25
02 yy2 xx2 10 60 30
03 yy3 xx3 15
...
Do any of you R wizards know how to do this? Many thanks for any help!