我花了很多时间在R中获取每一天的差异:
start <- as.Date(c("2013-02-26", "2013-03-26","2013-04-01","2013-04-26","2013-05-26"))
end <- as.Date(c("2013-03-25","2013-03-31","2013-04-25","2013-05-25","2013-06-25"))
per_cost <- c(3451380,3767052,3726900,4076868,3575311)
x <- data.frame(START_DAY=start, END_DAY=end, PER_COST=per_cost)
x$DIF_DAYS<- x$END_DAY-x$START_DAY
然后,我得到了这个:
START_DAY END_DAY PER_COST DIF_DAYS
1 2013-02-26 2013-03-25 3451380 27 days
2 2013-03-26 2013-03-31 3767052 5 days
3 2013-04-01 2013-04-25 3726900 24 days
4 2013-04-26 2013-05-25 4076868 29 days
5 2013-05-26 2013-06-25 3575311 30 days
我希望得到这个输出:
DATE PER_COST
2013-02-26 3451380
2013-02-27 3451380
2013-02-28 3451380
2013-02-29 3451380
...
2013-03-25 3451380
2013-03-26 3767052
2013-03-27 3767052
2013-03-28 3767052
如何实现此功能?