我有一年的每小时天气数据。我喜欢从中提取每日最大值,平均值等。所以我在这里寻求帮助。我遇到了以下主题:
convert hourly rainfall data into daily in specific time interval
我无法理解Pop的答案。由于我得分少于50分,我无法在那里添加评论。所以我发布这个问题。 任何人都可以解释这些命令吗?
fun <- function(s,i,j) { sum(s[i:(i+j-1)]) }
sapply(X=seq(1,24*nb_of_days,24),FUN=fun,s=your_time_serie,j=24)
答案 0 :(得分:1)
建议您使用dplyr
包进行聚合 - 请参阅以下内容:
rain<-read.table(sep="|",text="1970-01-05 00:00:00|1.0
1970-01-05 01:00:00|1.0
1970-01-05 02:00:00|1.0
1970-01-05 03:00:00|1.0
1970-01-05 04:00:00|1.0
1970-01-05 05:00:00|3.6
1970-01-05 06:00:00|3.6
1970-01-05 07:00:00|2.2
1970-01-05 08:00:00|2.2
1970-01-05 09:00:00|2.2
1970-01-05 10:00:00|2.2
1970-01-05 11:00:00|2.2
1970-01-05 12:00:00|2.2
1970-01-05 13:00:00|2.2
1970-01-05 14:00:00|2.2
1970-01-05 15:00:00|2.2
1970-01-05 16:00:00|0.0
1970-01-05 17:00:00|0.0
1970-01-05 18:00:00|0.0
1970-01-05 19:00:00|0.0
1970-01-05 20:00:00|0.0
1970-01-05 21:00:00|0.0
1970-01-05 22:00:00|0.0
1970-01-05 23:00:00|0.0
1970-01-06 00:00:00|0.0")
require(dplyr) # for aggregation
group_by(rain,day=as.Date(rain$V1)) %.%
summarise(total=sum(V2))
day total
1 1970-01-05 32
2 1970-01-06 0