[英]mean and sd of the day in R with xts
again I do have my df in xts and don't have names! 再次,我确实在xts中有我的df并且没有名字! (as far as I know there is no name anymore when setting as.POSIXct()):
(据我所知,设置as.POSIXct()时不再有名字了:
"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
I wanna calculate the mean and sd of the day - not of the whole df. 我想计算当天的平均值和sd - 而不是整个df。
df2<-period.apply(df, endpoints(df, "hours", 24), mean)
works but I am getting not the mean of one day - and how to deal with the standard deviation? 有效,但我不是有一天的意思 - 以及如何处理标准偏差? Thanks
谢谢
Does apply.daily
do what you want? 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
by(value,as.Date(df$timestamp),mean)
by(value,as.Date(df$timestamp),sd)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.