Aggregate daily level data to weekly level in R

前端 未结 5 739
无人及你
无人及你 2021-01-03 16:55

I have a huge dataset similar to the following reproducible sample data.

   Interval    value
1  2012-06-10   552
2  2012-06-11  4850
3  2012-06-12  4642
4          


        
5条回答
  •  没有蜡笔的小新
    2021-01-03 17:27

    If you mean the sum of of ‘value’ by week I think the easiest way to do it is to convert the data into a xts object as GSee suggested:

    data <- as.xts(data$value,order.by=as.Date(data$interval))
    weekly <- apply.weekly(data,sum)
    
                [,1]
    2012-06-10   552
    2012-06-17 23629
    2012-06-24 23872
    2012-07-01 23667
    2012-07-08 23552
    2012-07-10 10902
    

    I leave the formatting of the output as an exercise for you :-)

提交回复
热议问题