Let's say i have this df:
>df
ID V1 V2 V3
1 24 81 NA
2 22 34 32
3 88 NA NA
And i'd like to gather them like this (removing the NA's)
>df
ID VAR VAL
1 V1 24
1 V2 81
2 V1 22
2 V2 34
2 V3 32
3 V1 88
I've tried using gather
from plyr
but don't know how to keep the column id
. I've read their documentation with ?gather but still couldn't figure it out. Here's the simple code i'm using:
gather(df, key = id)