Aggregating, restructuring hourly time series data in R

Posted by Advait Godbole on Stack Overflow See other posts from Stack Overflow or by Advait Godbole
Published on 2012-03-26T04:49:17Z Indexed on 2012/03/26 17:29 UTC
Read the original article Hit count: 375

Filed under:
|

I have a year's worth of hourly data in a data frame in R:

> str(df.MHwind_load)   # compactly displays structure of data frame
'data.frame':   8760 obs. of  6 variables:
 $ Date         : Factor w/ 365 levels "2010-04-01","2010-04-02",..: 1 1 1 1 1 1 1 1 1 1 ...
     $ Time..HRs.   : int  1 2 3 4 5 6 7 8 9 10 ...
 $ Hour.of.Year : int  1 2 3 4 5 6 7 8 9 10 ...
     $ Wind.MW      : int  375 492 483 476 486 512 421 396 456 453 ...
 $ MSEDCL.Demand: int  13293 13140 12806 12891 13113 13802 14186 14104 14117 14462 ...
     $ Net.Load     : int  12918 12648 12323 12415 12627 13290 13765 13708 13661 14009 ...

While preserving the hourly structure, I would like to know how to extract

  1. a particular month/group of months
  2. the first day/first week etc of each month
  3. all mondays, all tuesdays etc of the year

I have tried using "cut" without result and after looking online think that "lubridate" might be able to do so but haven't found suitable examples. I'd greatly appreciate help on this issue.

© Stack Overflow or respective owner

Related posts about r

    Related posts about time-series