I have two data frames. One is like below:
D_Time Speed_BT Speed_GT
2016-09-12 00:15:00 23 60
2016-09-12 00:45:00 13 48
2016-09-12 01:30:00 13 25
The other one is like this:
D_Time Speed_AA Speed_DD
2016-09-12 00:30:00 29 17
2016-09-12 01:00:00 46 59
2016-09-12 01:30:00 36 51
I want to add the two data frames based on D_Time. So, it will look like the following table:
D_Time Speed_BT Speed_GT Speed_AA Speed_DD
2016-09-12 00:15:00 23 60 NA NA
2016-09-12 00:30:00 NA NA 29 17
2016-09-12 00:45:00 13 48 NA NA
2016-09-12 01:00:00 NA NA 46 59
2016-09-12 01:15:00 NA NA NA NA
2016-09-12 01:30:00 13 25 36 51
It will be great if I can add the 5th row like the way I have added in the data frame. However, If there is no other way then its okay.
I already have tried using this command:
add <- merge(df1, df2,by = "D_Time", all=TRUE)
But, the problem is it does not add properly. Speed_AA and Speed_DD value add in different rows where the time is different.
D_Time class is "POSIXct" "POSIXt".
Can anyone help me out?
Thanks in advance.