Binning Dates in R

后端 未结 1 1387
[愿得一人]
[愿得一人] 2020-12-06 01:55

I struggle with dates and times in R, but I am hoping this is a fairly basic task.

Here is my dataset:

> str(temp.df)
\'data.frame\':   74602 obs.         


        
相关标签:
1条回答
  • 2020-12-06 02:47

    Use the proper time series packages zoo and/or xts. This example is straight from the help pages of aggregate.zoo() which aggregates POSIXct seconds data every 10 minutes

     tt <- seq(10, 2000, 10)
     x <- zoo(tt, structure(tt, class = c("POSIXt", "POSIXct")))
     aggregate(x, time(x) - as.numeric(time(x)) %% 600, mean)
    

    The to.period() function in xts is also a sure winner. There are countless examples here on SO and on the r-sig-finance list.

    0 讨论(0)
提交回复
热议问题