Does apply.daily
do what you want?
> 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
Question
again I do have my df in xts and don't have names! (as far as I know there is no name anymore when setting 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.
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
Solution
Does apply.daily
do what you want?
> 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
OTHER TIPS
by(value,as.Date(df$timestamp),mean)
by(value,as.Date(df$timestamp),sd)