[R] Aggregate records to 10min
Rolf Fankhauser
rolf.fankhauser at gepdata.ch
Sat Jan 16 19:45:47 CET 2016
Hi
I would like to aggregate a rainfall series with 1min records (timestamp
and value of 0.1mm from a tipping bucket raingauge) to 10min values by
summing up the values.
# ptime is a POSIXlt datetime value with tz="GMT"
t10min <- 600*floor(as.integer(as.POSIXct(data$ptime))/600)
w10min <- tapply(data$value, format(as.POSIXct(t10min, tz="GMT", origin
= "1970-01-01"), "%Y-%m-%d %H:%M"), sum)
write.table(as.matrix(w10min),"data 10min.txt", row.names=TRUE,
col.names=FALSE, quote=FALSE)
This code works but I would like to have the result in datetime format
of %m/%d/%Y %H:%M. When I output this format the records are not
chronologically sorted but text-sorted because dimnames of w10min is of
type character (because of the format function).
Is there an easier way summing up the records to 10min records?
Thanks,
Rolf
More information about the R-help
mailing list