Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

r - Can't find function "across" in 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.

The code is as follows:

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))

It gives the following error: Error in across(2:ncol(.), as.numeric) : could not find function "across"

Does someone have a solution to this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...