1

我一直在与 cumsum 在多种条件下工作。在这种情况下,我需要为 、 和 一年中的每一天执行year运行site温度canopy总和treatemt_abbr。这是简化数据的示例:

  site year doy canopy power treatment_abbr airtemp_comb_nearby gdd10
  cfc 2009   1 closed     0             h2          -18.153490     0
  cfc 2009   2 closed     0             h2           18.153490     8
  cfc 2009   3 closed     0             h2           13.153490     3
  cfc 2009   1 open       0             ac           12.490        2
  cfc 2009   2 open       0             ac           16.912620     6
 hwrc 2012   1 closed     0             dc           11.146437     1
 hwrc 2012   2 closed     0             dc            2.005500     0
 hwrc 2012   3 closed     0             dc            2.5500       0
 hwrc 2012   4 closed     0             dc            22.1234      12
 hwrc 2012   5 closed     0             dc            2.005500     0

我的实际数据集非常大,所以我想使用 data.table 功能。在我看来,以下应该有效。它确实创建了新列“gddsum10”,但无法进行运行总和。知道我在这里做错了什么吗?

dt[order(doy), gddsum10:=cumsum(gdd10), by=c("year", "doy", "site", 
                                             "canopy", "treatment_abbr")]

我正在寻找与新专栏类似的东西"gddsum10"

  site year doy canopy power treatment_abbr airtemp_comb_nearby gdd10    gddsum10
  cfc 2009   1 closed     0             h2          -18.153490     0     0
  cfc 2009   2 closed     0             h2           18.153490     8     8
  cfc 2009   3 closed     0             h2           13.153490     3     11
  cfc 2009   1 open       0             ac           12.490        2     2
  cfc 2009   2 open       0             ac           16.912620     6     8
 hwrc 2012   1 closed     0             dc           11.146437     1     1
 hwrc 2012   2 closed     0             dc            2.005500     0     1
 hwrc 2012   3 closed     0             dc            2.5500       0     1
 hwrc 2012   4 closed     0             dc            22.1234      12    13
 hwrc 2012   5 closed     0             dc            2.005500     0     13
4

0 回答 0