【发布时间】:2021-03-17 17:06:33
【问题描述】:
我正在尝试在此处关注此堆栈帖子:How to get sum of values every 8 days by date in data frame in R
有谁知道为什么这不起作用?
library(xts)
set.seed(123)
property_damages_in_dollars <- rnorm(731,100,10)
date_decision_made <- format(as.Date(date_decision_made), "%Y/%m/%d")
other_damages_in_dollars <- rnorm(731,10,10)
final_data <- data.frame(date_decision_made, other_damages_in_dollars, property_damages_in_dollars)
ep <- endpoints(final_data,'days',k=8)
a = period.apply(x=final_data,ep,FUN=sum )
注意:对于两个变量,这段代码可以工作吗?
dat <- xts(cbind(final_data$property_damages_in_dollars, final_data$other_damages_in_dollars),
as.Date(final_data$date_decision_made, '%Y/%m/%d'))
ep <- endpoints(dat,'days',k=8)
a = period.apply(x=dat,ep,FUN=sum )
【问题讨论】:
标签: r time-series aggregate xts