提问人:cliu 提问时间:2/7/2023 更新时间:2/7/2023 访问量:51
使用 dplyr 的多个列存在多个滞后的问题
Problem of multiple lags for a number of columns with dplyr
问:
我正在尝试复制为网站上的多个列创建多个滞后的示例(https://dplyr.tidyverse.org/reference/across.html)。但是,当我尝试他们的代码时:dplyr
multilag <- function(x, lags = 1:3) {
names(lags) <- as.character(lags)
purrr::map_dfr(lags, lag, x = x)
}
iris %>%
group_by(Species) %>%
mutate(across(starts_with("Sepal"), multilag, .unpack = TRUE)) %>%
select(Species, starts_with("Sepal"))
我收到此错误:
Error in `mutate()`:
! Problem while computing `..1 = across(starts_with("Sepal"), multilag, .unpack = TRUE)`.
i The error occurred in group 1: Species = setosa.
Caused by error in `across()`:
! Problem while computing column `Sepal.Length`.
Caused by error in `fn()`:
! unused argument (.unpack = TRUE)
Run `rlang::last_error()` to see where the error occurred.
有人知道问题是什么以及如何解决吗?
这是我的会议信息:
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
答: 暂无答案
评论
dplyr
.unpack
dplyr 1.1.0