Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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)
您好,我有 2 列带有开始和结束日期的列,并且相应的剂量是在一定时间内施用的。如何计算差异并打印出这两个日期之间的持续时间。我已经给出了预期结果的示例代码。
谢谢你。
我们可以使用Map将两个向量的对应序列放入 alist中,然后cbind是unlistted 'lst' 和replicated 'd'(基于lengths'lst'
Map
list
cbind
unlist
rep
lengths
lst <- Map(`:`, st_day, endday) out <- cbind(unlist(lst), rep(d, lengths(lst)))