首页 > 解决方案 > 累积常设作物随时间变化公式

问题描述

这里的园艺博士生,从事一项涉及葡萄根动力学的研究。

我正在尝试计算三年内每次观察期间的运行累积根数(活根-死+新生)。我总共进行了 43 次观察。会话 2 到 43 是出生会话(新根诞生),会话 3 到 44 是一些根死亡或消失但我们仍然有活根的会话。

我在计算累积总和方面取得了一定的成功,但还没有开发出可以让我获得运行累积立项作物的代码。

这是我迄今为止开发的:

# make new dataframe
standingcrop <- all_roots %>%
  select(BirthSession, roots, ComboDeadGone, Tube, Censored) %>%
  filter(!is.na(roots)) %>%
  arrange(BirthSession)

# calculate cumulative sum of roots by birthsession
standingcrop <- standingcrop %>%
  group_by(BirthSession, Tube) %>%
  mutate("standingcrop" = cumsum(roots))

#calculate cumulative difference - difference by deathsession

standingcrop2 <- all_roots %>%
  select(BirthSession, roots, ComboDeadGone, Tube, Censored) %>%
  filter(!is.na(roots)) %>%
  arrange(ComboDeadGone)

standingcrop2 <- standingcrop2 %>%
  group_by(BirthSession > 2, Tube) %>%
  mutate("standingcrop" = cumulDiff(roots))

有没有人知道如何在每次观察期间获得累积的常设作物(在给定观察期间出生的根数 - 在该观察期间死亡或消​​失的根数?)?

太感谢了!

标签: r

解决方案


推荐阅读