[R] creating chron object aggregates (e.g. sums by day)

Olivier Collignon olivier at loudcloud.com
Tue Oct 30 01:20:27 CET 2001


What is the recommended/optimal way to perform aggregates on data frames
with chron objects?

Here is an example:

>raw.data
1 07/09/01   4000
2 07/09/01   2000
3 07/11/01   1000
4 07/13/01   800
5 07/13/01   700
6 07/16/01   600
7 07/17/01   500

I'm trying to construct a function that would first aggregate the data
(second column) by day (grouping by the first column) according to a
function (here "sum", but could be "max" or other)

>chronaggregate(raw.data, sum, "days")   #(used "days" since 07/09/01 is
short for 07/09/01 00:00:00, but could be 07/09/01 00:12:34)
1 07/09/01   6000      << sum of data values for day 07/09/01 from
raw.data
2 07/11/01   1000
3 07/13/01   1500      << sum of data values for day 07/13/01 from
raw.data
4 07/16/01   600
5 07/17/01   500

and insert 0 values for days without data:

1 07/09/01   6000
2 07/10/01   0              << inserted record
3 07/11/01   1000
4 07/12/01   0              << inserted record
5 07/13/01   1500
6 07/14/01   0              << inserted record
7 07/15/01   0              << inserted record
8 07/16/01   600
9 07/17/01   500

Is there a simple way to do this?

Thanks,

--
-Olivier

--
Olivier Collignon
Loudcloud, Inc.
olivier at loudcloud.com



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list