找不到“跨越"功能在 mutate() [英] Can't find function "across" in mutate()

查看:28
本文介绍了找不到“跨越"功能在 mutate()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试清理我们的数据.我们已经收集了数据集,除了最后一点代码之外,几乎所有东西都可以正常工作.它说它无法找到该功能.

We're trying to clean up our data. We've collected the dataset and almost everything works, apart from the last bit of code. It says it can not find the function across.

代码如下:

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, "(.+)
")) %>%
  mutate(variable = str_replace(variable, "\r", "")) %>%
  distinct() %>%
  pivot_wider(names_from = variable, values_from = value) %>%
  mutate(across(2:ncol(.), as.numeric))

它给出了以下错误:cross(2:ncol(.), as.numeric) 中的错误:找不到函数across"

有人能解决这个问题吗?

Does someone have a solution to this problem?

推荐答案

across 功能仍然只在 dplyr 的开发版本中可用,目前还没有在 CRAN 上(参考).这导致了两种选择:

The across function is still only available in the development version of dplyr, not on CRAN yet (reference). This leads to two options:

  • (A) 安装 开发版 通过运行 install.packages("devtools");devtools::install_github("tidyverse/dplyr").那么你的代码应该可以工作了.

  • (A) Install dev version by running install.packages("devtools"); devtools::install_github("tidyverse/dplyr"). Then your code should work.

(B) 将您的代码转换回之前的公式,而不是使用 across(参见背景 此处在如何转换现有代码?"部分中).

(B) Convert your code back to earlier formula, not using across (see background here within the section 'How do you convert existing code?').

附:在以后的问题中,请考虑提供一个可重现的示例.

P.S. In future questions, consider providing a reproducible example.

这篇关于找不到“跨越"功能在 mutate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆