找不到“跨"函数在mutate()中 [英] Can't find function "across" in mutate()

查看:98
本文介绍了找不到“跨"函数在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, "(.+)\r")) %>%
  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)中的错误:找不到函数"cross"

有人可以解决这个问题吗?

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.在以后的问题中,请考虑提供一个可复制的示例.

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

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

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