Re: [R] Sum per hour

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 24 May 2007 15:19:40 -0400

We could do it using either POSIXct or chron:

library(zoo)

# POSIXct
z <- zoo(precipitation, as.POSIXct(time, tz = "GMT")) aggregate(z, function(x) as.POSIXct(trunc(x, "hour")), sum)

# chron
library(chron)
z <- zoo(precipitation, as.chron(as.POSIXct(time, tz = "GMT")) aggregate(z, function(x) chron(trunc(times(x), "01:00:00")), sum)

On 5/24/07, jessica.gervais_at_tudor.lu <jessica.gervais_at_tudor.lu> wrote:
>
> Dear all,
>
> I have a list of precipitation record and a list of time
> I would like to sum them up per hour, or per day.
> Does such a function exist ?
>
>
> example:
> time<-c("2000-10-03 14:00:00","2000-10-03 14:10:00","2000-10-03
> 14:20:00","2000-10-03 15:30:00","2000-10-03 16:40:00","2000-10-03
> 16:50:00","2000-10-03 17:00:00","2000-10-03 17:10:00","2000-10-03
> 17:20:00","2000-10-03 18:30:00","2000-10-04 14:00:00","2000-10-04
> 14:10:00","2000-10-04 14:20:00","2000-10-04 15:30:00","2000-10-04
> 16:40:00","2000-10-04 16:50:00","2000-10-04 17:00:00","2000-10-04
> 17:10:00","2000-10-04 17:20:00","2000-10-04 18:30:00")
>
> precipitation<-c(0,0.1,0,0,0,0,0.2,0.3,0.5,6,7,8,9,1,0,0,0,0,1,0)
>
> DATA<-cbind(time,precipitation)
>
> ... ?
> how to sum up per hour ?
>
> Thanks in advance
>
> Jessica
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 24 May 2007 - 19:30:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 May 2007 - 09:31:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.