Calculate average monthly total by groups from data.table in R

后端 未结 3 1987
暖寄归人
暖寄归人 2020-12-30 07:29

I have a data.table with a row for each day over a 30 year period with a number of different variable columns. The reason for using data.table is that the .csv file I\'m usi

3条回答
  •  -上瘾入骨i
    2020-12-30 08:09

    If you're not looking for complicated functions and just want the mean, then the following should suffice:

    DT[, sum(Runoff) / length(unique(year(Date))), list(Key, month(Date))]
    #   Key month       V1
    #1:   A     1 4.366667
    #2:   B     1 3.266667
    

提交回复
热议问题