【发布时间】:2018-01-09 16:51:42
【问题描述】:
我有这样的数据。
spot3new<- aggregate(spot3$Price~spot3$Date, spot3, sum)
head(spot3new)
spot3$Date spot3$Price
1 2011-01-01 -16.32
2 2011-01-02 861.11
3 2011-01-03 1381.69
4 2011-01-04 1497.08
5 2011-01-05 1228.44
6 2011-01-06 1226.26
在这里,我按日期汇总每小时的价格。所以 24 小时的价格是加在一起的。现在我想将它们除以小时数以得出平均价格。 所以我就这么做了。
spot3newD<- data.frame(spot3new$`spot3$Date`, spot3new$`spot3$Price`/24)
> head(spot3newD)
spot3new..spot3.Date. spot3new..spot3.Price..24
1 2011-01-01 -0.68000
2 2011-01-02 35.87958
3 2011-01-03 57.57042
4 2011-01-04 62.37833
5 2011-01-05 51.18500
6 2011-01-06 51.09417
但我意识到,在 48000 次观察中,有一些缺失值。因此,如果我除以 24,它不会产生“每日平均价格”,因为从我的数据中间的某个地方,价格会由于缺失值而被拉动或推高。
所以我不想分割我的数据by 24。我想将 2015-12-31 到 2011-01-02 的每一天的by date or days 分开,这样他们就不会误算了。
谁能帮我语法?
非常感谢您。
【问题讨论】: