1
我想更新與比較的另一個數據幀中的audit
數據幀:總和計數
test
:中數量的數據幀患者對於特定日期:
test <- data.frame(
date=as.Date(c("2012-12-12","2012-12-29","2013-01-15")),
patients=c(4,7,3)
)
date patients
1 2012-12-12 4
2 2012-12-29 7
3 2013-01-15 3
audit
:審計的數據幀日期:
audit <- data.frame(date=as.Date(c("2012-12-31","2013-01-31")),
count=c(NA))
date count
1 2012-12-31 NA
2 2013-01-31 NA
問:audit$count
應在test
UP TO audit$date
患者的總數是多少?
這不起作用:
audit$count <- sum(test[test$date < audit$date,]$patients)
如何最有效地做到這一點?
+1!以確切的答案擊敗我! (即使有點晚,恭喜10k) – agstudy 2013-03-18 08:42:07
@agstudy謝謝。我想,SO上的所有R用戶都無法跟上你的速度。 ;-) – 2013-03-18 08:57:12