Get monthly means from dataframe of several years of daily temps

后端 未结 3 647
星月不相逢
星月不相逢 2020-12-04 00:43

I have daily temperature values for several years, 1949-2010. I would like to calculate monthly means. Here is an example of the data:

head(tmeasmax)
TIMESTE         


        
3条回答
  •  执念已碎
    2020-12-04 01:21

    You can use the lubridate package to create a new factor variable consisting of the year-month combinations, then use aggregate.

    library('lubridate')
    
    tmeasmax2 <- within(tmeasmax, {
            monthlies <- paste(year(TIMESTEP),
                               month(TIMESTEP))
    })
    
    aggregate(tmeasmax2, list(monthlies), mean, na.rm = TRUE)
    

提交回复
热议问题