I have a data frame which has five columns like below:
id p1 p2 time group
___ ___ ___ ____ _______
1 1.2 1.9 2016-10-09 01:00:00 1
1 1.8 1.3 2016-10-09 03:00:00 1
1 1.2 1.9 2016-10-09 03:00:00 2
1 1.8 1.3 2016-10-09 06:00:00 2
3 1.2 1.9 2016-10-09 09:00:00 1
3 1.8 1.3 2016-10-09 12:00:00 1
From this I need to reshape long to wide for each id and each group which is like below:
id group p1_start p2_start time_start p1_complete p2_complete time_complete
___ ______ __________ ________ ___________ ________ ______ __________ ________
1 1 1.2 1.9 2016-10-09 01:00:00 1.2 1.9 2016-10-09 03:00:00
1 2 1.2 1.9 2016-10-09 06:00:00 1.2 1.9 2016-10-09 03:00:00
3 1 1.2 1.9 2016-10-09 09:00:00 1.2 1.9 2016-10-09 12:00:00
So I tried with
reshape(DT, idvar = c("id","group"), timevar = "group", direction = "wide")
But this resulted in what not expected output.
Any help is appreciated.