I have a data.table with two parameters(date and statues), now I want to insert new rows for the whole day based on the original table.
data rules:
- the Status column contains only "0" and "1"
- the time-stamp which hasnt been recorded in the table is same with its next nearest tiemstamp in the table.
- the Date column is always increase by time :)
For example, a simple input:
create the data with the code below:
dd <- data.table(date = c("2015-07-01 00:00:02", "2015-07-01 00:00:04", "2015-07-01 00:00:08"),
status = c(0,1,0))
the out put is :
my solution:
- calculate the time difference for each two rows, then save in a new column called time_diff
- insert new row in the loop based on the time_diff
it could work, but the problem is the calculation time is too long, since so many loops. I thinks there could be an easier solution for this case
Any help or suggestion would be greatly appreciated:)
thanks!