使用r每天添加价值

发布于 2025-01-26 12:55:36 字数 46 浏览 2 评论 0原文

data_frame:

我正在尝试创建一个列,该列每天都会对诸如

data_frame: counties

I'm trying to create a column that does a cumulative sum day by day for the number of cases like

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里°也失望 2025-02-02 12:55:36

您不想按日期进行分组,因为您希望这些集量跨越多天。我认为您确实想按州和县进行分组。

county_by_day <- counties %>%
  arrange(state, county, date) %>%
  group_by(state, county) %>%
  mutate(total = cumsum(cases))

You don't want to group by date because you want the cumsum to span multiple days. I assume you do want to group by state and county.

county_by_day <- counties %>%
  arrange(state, county, date) %>%
  group_by(state, county) %>%
  mutate(total = cumsum(cases))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文