Reputation: 31
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, "(.+)\r")) %>%
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?
Upvotes: 3
Views: 5863
Reputation: 262
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 dev version by running install.packages("devtools"); devtools::install_github("tidyverse/dplyr")
. Then your code should work.
(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.
Upvotes: 4