[R] average at specific hour "endpoints" of the day
Massimo Bressan
massimo.bressan at arpa.veneto.it
Thu Apr 6 10:51:26 CEST 2017
hello
given my reproducible example
#---
date<-seq(ISOdate(2017,1, 1, 0), by="hour", length.out = 48)
v1<-1:48
df<-data.frame(date,v1)
#--
I need to calculate the average of variable v1 at specific hour "endpoints" of the day: i.e. at hours 6.00 and 22.00 respectively
the desired result is
date v1
01/01/17 22:00 15.5
02/01/17 06:00 27.5
02/01/17 22:00 39.5
at hour 06:00 of each day the average is calculated by considering the 8 previous records (hours from 23:00 to 6:00)
at hour 22:00 of each day the average is calculated by considering the 16 previous records (hours from 7:00 to 22:00)
any hint please?
I've been trying with some functions within the "xts" package but withouth much result...
thanks for the help
[[alternative HTML version deleted]]
More information about the R-help
mailing list