我正在尝试计算每个国家/地区的预期寿命增加量,但我无法让 diff() 函数在这里工作。我还尝试了滞后/超前功能,但我无法使用它。任何建议表示赞赏。
\nlibrary(gapminder)\ngm <- gapminder\ninclife <- gm %>%\n drop_na(lifeExp)%>%\n group_by(country) %>%\n select(country, year, lifeExp) %>%\n mutate(inc = diff(lifeExp))\nRun Code Online (Sandbox Code Playgroud)\n这是我得到的错误
\nError in `mutate()`:\n! Problem while computing `inc = diff(lifeExp)`.\n\xe2\x9c\x96 `inc` must be size 12 or 1, not 11.\n\xe2\x84\xb9 The error occurred in group 1: country = "Afghanistan".\nRun `rlang::last_error()` to see where the error occurred.\nRun Code Online (Sandbox Code Playgroud)\n