[R-SIG-Finance] Aggregating Statistics By Time Interval

Gabor Grothendieck ggrothendieck at gmail.com
Wed Aug 1 15:16:24 CEST 2007


Something similar was just discussed this morning:
https://www.stat.math.ethz.ch/pipermail/r-help/2007-August/137695.html


On 8/1/07, Rory Winston <rory.winston at gmail.com> wrote:
> Hi all
>
> I have a question about aggegating statistics by time intervals. I have a
> data set with 3 columns : time, bid, and ask. Time is specified as a
> millisecond timestamp since epoch. I would like to compute summary
> statistics for the data set on an hourly basis. Here is what I have tried so
> far:
>
> # Data is in pricedata
>
> t <- ISODatetime(1970, 1, 1, 0, 0, 0) + pricedata$time
> agg <- aggregate(pricedata$spread, list(byhour=format(t, "%Y-%m %H")), mean)
>
> This seems to do what I want - however, what really want to do is more
> specific: I would like to be able to extract a subset of the data frame
> pricedata, and not just the aggregated entries - for instance, instead of
> just extracting pricedata$spread by hour, I would like to extract a slice of
> columns, e.g. pricedata$spread and pricedata$time on an hourly basis, and
> pass these into a function that can compute a time-weighted average spread,
> for instance. Does anyone know an elegant way to do this? I have a feeling
> zoo may do what I want, but I'm new to zoo ...
>
> Cheers
> Rory
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list