Thanks in advance.
I am trying to add missing date values that were not included in a observation period for three different individuals.
My data look like t
Try this.. This will add missing Dates with proper IDs and remaining fields as 0
library(data.table)
library(plyr)
dtPostData = data.table(PostData)
minmaxTab = dtPostData[,list(minDate=min(Date),maxDate=max(Date)),by=IndID]
df = lapply(1:nrow(minmaxTab),function(x) {
temp = seq(minmaxTab$minDate[x],minmaxTab$maxDate[x],by=24*60*60)
temp = temp[!(temp %in% dtPostData[IndID == minmaxTab$IndID[x],]$Date)]
data.table(IndID = minmaxTab$IndID[x], Date = temp, Event = 0, Number = 0, Percent = 0)
})
df <- ldply(x, data.frame)
df
#Results
IndID Date Event Number Percent
1 P01 2011-03-05 0 0 0
2 P01 2011-03-06 0 0 0
3 P01 2011-03-07 0 0 0
4 P01 2011-03-08 0 0 0
5 P01 2011-03-09 0 0 0
6 P01 2011-03-10 0 0 0
7 P01 2011-03-12 0 0 0
8 P01 2011-03-16 0 0 0
9 P03 2011-07-10 0 0 0