What is an efficient method for partitioning and aggregating intervals from timestamped rows in a data frame?

后端 未结 3 696
小鲜肉
小鲜肉 2020-12-03 09:07

From a data frame with timestamped rows (strptime results), what is the best method for aggregating statistics for intervals?

Intervals could be an hour, a day, et

3条回答
  •  执念已碎
    2020-12-03 09:52

    Use a time series package. The xts package has functions designed specifically to do that. Or look at the aggregate and rollapply functions in the zoo package.

    The rmetrics ebook has a useful discussion, including a performance comparison of the various packages: https://www.rmetrics.org/files/freepdf/TimeSeriesFAQ.pdf

    Edit: Look at my answer to this question. Basically you need to truncate every timestamp into a specific interval and then do the aggregation using those new truncated timestamps as your grouping vector.

提交回复
热议问题