我们正在努力清理数据。我们已经收集了数据集,除了最后一段代码外,几乎所有的东西都能工作。它说它找不到跨的函数。
代码如下:
cleandata <- data1 %>%
pivot_longer(3:173, names_to = "variable", values_to = "value") %>%
select(-2) %>%
mutate(year = as.numeric(str_extract(variable, "[0-9]{4}"))) %>%
mutate(variable = str_extract(variable, "(.+)r")) %>%
mutate(variable = str_replace(variable, "\r", "")) %>%
distinct() %>%
pivot_wider(names_from = variable, values_from = value) %>%
mutate(across(2:ncol(.), as.numeric))
它给出以下错误:Error in across(2:ncol(.), as.numeric) : could not find function "across"
有人能解决这个问题吗?
across
函数仍然仅在dplyr
的开发版本中可用,尚未在CRAN上可用(参考(。这导致了两种选择:
-
(A(通过运行
install.packages("devtools"); devtools::install_github("tidyverse/dplyr")
安装开发版本。那么您的代码应该可以工作了。 -
(B( 将代码转换回以前的公式,而不使用
across
(请参阅"如何转换现有代码?"一节中的背景(。
p.S.在以后的问题中,考虑提供一个可重复的例子。