Get monthly means from dataframe of several years of daily temps

后端 未结 3 638
星月不相逢
星月不相逢 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:19

    Here's a quick data.table solution. I assuming you want the means of MEAN.C. (?)

    library(data.table)
    setDT(tmeasmax)[, .(MontlyMeans = mean(MEAN.C.)), by = .(year(TIMESTEP), month(TIMESTEP))]
    #    year month MontlyMeans
    # 1: 1949     1    11.71928
    

    You can also do this for all the columns at once if you want

    tmeasmax[, lapply(.SD, mean), by = .(year(TIMESTEP), month(TIMESTEP))]
    #    year month  MEAN.C. MINIMUM.C. MAXIMUM.C. VARIANCE.C.2. STD_DEV.C.      SUM COUNT
    # 1: 1949     1 11.71928     11.095   12.64667     0.2942481   0.482513 1.426652     6
    

提交回复
热议问题