I have a data table in R that I'm currently working with that contains thousands of pids each tracked over a period of time. Within this data table is an agedays column. I need to ensure that each pid has a row corresponding to the following agedays values :
ageday_values<-c(61, 91, 183, 274, 365, 457, 548, 639, 731)
If the pid already has a row corresponding to an agedays value above then that specific row should not be altered in anyway. If the row isn't present, then when the row is inserted, all columns should hold an NA value with exception to the agedays column of that specific row.
I know how to insert rows over a specific range of values, but am unsure how to do so over a vector of specific values. Does anyone have some insight on how to do this?
small subset of data :
DT <- data.table(pid = c(1,1,1,1,2,2,2,2,3,3,3,3),
agedays = c(25,50,61,457,37,365,731,50,61,457,639,731),
wt = c(1.2,1.5,1.7,2.0,4.5,6.7,6.8,6.7,4.5,6.6,8.9,6.7),
ht = c(3.2,1.8,6.7,2.8,3.5,7.7,9.8,1.7,6.9,3.8,0.9,4.7))