[R] Aggregate records to 10min

2016-01-16 Thread Rolf Fankhauser

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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Aggregate records to 10min

2016-01-17 Thread Fankhauser GEP Data Consulting

Hi Jim,
Thanks a lot! It works now. I didn't remember how to access the 
datetimes in w10min. names(...) is the solution!


Rolf

Jim Lemon wrote:

Hi Rolf,
If I get the above, perhaps if you change the names of w10min after 
applying the calculation:


raindata<-data.frame(value=round(runif(60,0,4),1),
ptime=paste("2016-01-17 ","15:",0:59,sep=""))
t10min <- 600*floor(as.integer(as.POSIXct(raindata$ptime))/600)
w10min <- tapply(raindata$value,t10min,sum)
names(w10min)<-format(as.POSIXct(as.numeric(names(w10min)),
 tz="AEST",origin="1970-01-01"),"%m/%d/%Y %H:%M")

Jim


On Sun, Jan 17, 2016 at 5:45 AM, Rolf Fankhauser 
mailto:rolf.fankhau...@gepdata.ch>> wrote:


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

__
R-help@r-project.org  mailing list --
To UNSUBSCRIBE and more, see
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.





--
__

Fankhauser GEP Data Consulting
Hegenheimerstrasse 129
4055 Basel

Tel:++41-(0)61-321-4525
Mobile: ++41-(0)79-440-7706
rolf.fankhau...@gepdata.ch
www.gepdata.ch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.