使用dplyr的铅和滞后问题
我有一个数据框架,其中有365行反映日历年的数据。我试图将县名列转换为一排。数据框架不包含任何缺失的值。
我尝试使用以下代码将其移动,但是结果表的值全是Na。
covid_shift <- covid_pivot %>%
mutate(Maricopa = lag(Maricopa), Cook = lag(Cook), Harris = lag(Harris))
有人知道可能是什么问题吗?
I have a data frame with data that looks like this that has 365 rows reflecting the calendar year. I am trying to shift the county name columns up by one row. The data frame doesn't contain any missing values.
I tried using the following code to shift it, but the resulting table has values that are all NA.
covid_shift <- covid_pivot %>%
mutate(Maricopa = lag(Maricopa), Cook = lag(Cook), Harris = lag(Harris))
Does anyone know what might be the issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
covid_pivot
按日期分组,并且每个组中的每一组都有一行,因此铅和滞后函数返回na。尝试:
您还可以考虑使用()使用
Since
covid_pivot
is grouped by date, and each of these groups has one row, the lead and lag functions return NA.Try:
You might also consider using
across()