I have 2 data frames: "start.date" and "death.date". Each include 2 columns "numid" (a numeric id) and a "date" column. "start.date" is a dataset that records start of disease for each numid. "death.date" includes only those numid in "start.date" that died on the date in death.date$date.
I need to calculate the difference (=survival) between start.date and death.date for those with the same numid.
This is what I wrote:
tempi<-as.numeric(factor(start.date$numid))
tempj<-as.numeric(factor(death.date$numid))
for(i in tempi){
for(j in tempj){
surviv[i]<-ifelse(colic.date$numid[i]==death.date$numid[j],
death.date$date.death[j]-colic.date$date.colic[i],
"alive")
}
}
My issue here I think is that surviv[i] only keeps the last value of death.date$numid[j] but I can not find a way out. Anyone could shine some light on this please? There are probably easier ways to do this (it runs very slow - even with the wrong result)
Apologies if this is has been discussed somewhere I just could not find anything that works with my data.
Cheers Marco