Reputation: 65
st_day<-c(1,5,10)
endday<-c(4,9,15)
d<-c(1,2,3)
data<-cbind(st_day,endday,d)
days1<-c(1:15)
dose1<-rep(c(1,2,3),each=5)
result <- cbind(days1,dose1)
Hello I have 2 coulmns with starts and end dates and corresponding dose with was a administered for certain duration. How can compute the difference and print out the duration between these two dates. I have given a sample code the expected result.
Thank you.
Upvotes: 0
Views: 47
Reputation: 887118
We can use Map
to get the corresponding sequence of the two vectors into a list
, then cbind
the unlist
ted 'lst' and the rep
licated 'd' (based on the lengths
of 'lst'
lst <- Map(`:`, st_day, endday)
out <- cbind(unlist(lst), rep(d, lengths(lst)))
Upvotes: 1