Calculating hourly averages from a multi-year timeseries

前端 未结 3 1292
栀梦
栀梦 2021-01-03 07:47

I have a dataset filled with the average windspeed per hour for multiple years. I would like to create an \'average year\', in which for each hour the average windspeed for

3条回答
  •  -上瘾入骨i
    2021-01-03 08:27

    You can use substr to extract the part of the date you want, and then use tapply or ddply to aggregate the data.

    tapply(
      data.multipleyears$Windspeed, 
      substr( data.multipleyears$DATETIME, 6, 19), 
      mean 
    )
    # 01-01 01:00:00 02-29 12:00:00 05-03 09:00:00 
    #              9              3              5 
    
    library(plyr)
    ddply(
      data.multipleyears, 
      .(when=substr(DATETIME, 6, 19)), 
      summarize, 
      Windspeed=mean(Windspeed)
    )
    #             when Windspeed
    # 1 01-01 01:00:00         9
    # 2 02-29 12:00:00         3
    # 3 05-03 09:00:00         5
    

提交回复
热议问题