R rollapply bottom to top?

烈酒焚心 提交于 2019-12-06 10:35:53

This is closer to what you want:

df1[is.na(df1)] = 0 ##This is how you're actually treating it!
df1 = data.frame(df1)


> df2 = apply(df1[nrow(df1):1,], 2, function(x) c(x[1], x[1]-cumsum(x[-1])))
> df2 = df2[nrow(df2):1,]
> df2
     Tree001 Tree002 Tree003
2008   31.28   30.22   51.47
2009   32.90   32.65   52.94
2010   36.86   38.23   56.43
2011   41.75   45.43   60.75
2012   48.36   54.73   60.75
RBH    57.15   66.60   60.75
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!