Hi,

I am new to R and wondering how I can subset and average time series data based on given irregular time periods:

Say I have a time series of a measured variable "x" (hourly data) in "values.csv" with columns "date" and "x" which I would like to average within certain irregular time periods ("events"), given in "events.csv" with columns "EventID", "start", and "stop" (where start and stop indicate the start and stop dates of the corresponding event).

What I usually do is to load the two csvs into a database and then perform an SQL statement like this:

SELECT a.EventID, avg(b.x) from events as a, values as b WHERE b.date between a.start and a.stop GROUP BY a.EventID

This gives a table with the EventIDs and the corresponding mean values of x as an output.

As my data are not that large I would like to avoid the database and do the averaging in R but I cannot find the way of doing this in R.

I would appreciate any advice to set me on track.

Thanks,
Dominik

______________________________________________
R-help@r-project.org 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.

Reply via email to