I am facing problem in transforming data from columns to row or wide format. My dataframe look like as below
V1 V2 V3 V4
1 1 2.041 NA
1 123 5.190 NA
1 366 9.500 NA
1 1462 16.800 NA
1 2558 23.500 88
2 1 2.466 NA
2 123 5.440 NA
2 366 9.000 NA
2 2558 18.600 91
....
I would like to transform it to as below
1 1 2.041 123 5.190 366 9.500 1462 16.800 2558 23.500 88
2 1 2.466 123 5.440 366 9.000 NA NA 2558 18.600 91
Or
1 1 2.041 NA 123 5.190 NA 366 9.500 NA 1462 16.800 NA 2558 23.500 88
2 1 2.466 NA 123 5.440 NA 366 9.000 NA NA NA NA 2558 18.600 91
I have tried couple of option with dcast like below but its not working out well.
dcast(data,V1~.)
dcast(data,V1~V2+V3+V4)