Aggregating, restructuring hourly time series data in R

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. Edit: a sample of data in the data frame is below: Date Hour.of.Year Wind.MW datetime 1 2010-04-01 1 375 2010-04-01 00:00:00 2 2010-04-01 2 492 2010-04-01 01:00:00 3 2010-04-01 3 483 2010-04-01 02:00:00 4 2010-04-01 4 476 2010-04-01 03:00:00 5 2010-04-01 5 486 2010-04-01 04:00:00 6 2010-04-01 6 512 2010-04-01 05:00:00 7 2010-04-01 7 421 2010-04-01 06:00:00 8 2010-04-01 8 396 2010-04-01 07:00:00 9 2010-04-01 9 456 2010-04-01 08:00:00 10 2010-04-01 10 453 2010-04-01 09:00:00 .. .. ... .......... ........ 8758 2011-03-31 8758 302 2011-03-31 21:00:00 8759 2011-03-31 8759 378 2011-03-31 22:00:00 8760 2011-03-31 8760 356 2011-03-31 23:00:00 EDIT: Additional time-based operations I would like to perform on the same dataset 1. Perform hour-by-hour averaging for all data points i.e average of all values in the first hour of each day in the year. The output will be an "hourly profile" of the entire year (24 time points) 2. Perform the same for each week and each month i.e obtain 52 and 12 hourly profiles respectively 3. Do seasonal averages, for example for June to September
This is purely R programming related question, with no statistical content. We migrate such questions to stackoverflow, since here we have more programmers.

以上就是Aggregating, restructuring hourly time series data in R的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏