fill W id X T
1 403 29730 100 111
1 8395 10766 100 92
1 4170 14291 100 98
1 2768 20506 200 110
1 3581 15603 100 112
6 1 10504 200 87
9 48 29730 100 89
1 4790 10766 200 80
This is a slightly modified random sample from my actual data. I'd like:
id X T 403 8395 ....
29730 100 111 1
10766 100 92 1
14291 100 98
20506 200 110
15603 100 112
10504 200 87
29730 100 89
10766 200 80
Notice ID 29730
is both in T 89
and 111
. I think this should just be reshape2::dcast
however
data_wide <- reshape2::dcast(data_long, id + T + X ~ W, value.var = "fill")
gives an illogical result. Is there generally a to keep the same ID at T1 and T2 while casting a data frame?