Aggregation by time period in lubridate

后端 未结 4 525
青春惊慌失措
青春惊慌失措 2021-01-05 11:18

This question asks about aggregation by time period in R, what pandas calls resampling. The most useful answer uses the XTS package to group by a given time period, applying

4条回答
  •  没有蜡笔的小新
    2021-01-05 12:05

    Using ddply from plyr package:

    library(plyr)
    bikecounts$Date<-with(bikecounts,as.Date(Date, format = "%m/%d/%Y"))
    x<-ddply(bikecounts,.(Date),summarise, sumnorth=sum(Northbound),sumsouth=sum(Southbound))
    
    
     > head(x)
            Date sumnorth sumsouth
    1 2012-10-02     1165      773
    2 2012-10-03     1761     1760
    3 2012-10-04     1767     1708
    4 2012-10-05     1590     1558
    5 2012-10-06      926     1080
    6 2012-10-07      951     1191
    
    
     > tail(x)
              Date sumnorth sumsouth
    298 2013-07-26     1964     1999
    299 2013-07-27     1212     1289
    300 2013-07-28      902     1078
    301 2013-07-29     2040     2048
    302 2013-07-30     2314     2226
    303 2013-07-31     2008     2076
    

提交回复
热议问题