"2012-04-09 05:00:00",2
"2012-04-09 09:00:00",4
"2012-04-09 12:00:00",5
"2012-04-09 22:00:00",0
"2012-04-10 04:00:00",0
"2012-04-10 06:00:00",3
"2012-04-10 08:00:00",0
"2012-04-10 12:00:00",1
我想计算当天的平均值和sd - 而不是整个df。
df2<-period.apply(df, endpoints(df, "hours", 24), mean)
有效,但我不是有一天的意思 - 以及如何处理标准偏差? 感谢
答案 0 :(得分:2)
apply.daily
能做你想做的吗?
> apply.daily(df, mean)
[,1]
2012-04-09 22:00:00 2.75
2012-04-10 12:00:00 1.00
> apply.daily(df, sd)
[,1]
2012-04-09 22:00:00 2.217356
2012-04-10 12:00:00 1.414214
答案 1 :(得分:1)
by(value,as.Date(df$timestamp),mean)
by(value,as.Date(df$timestamp),sd)