Robin Schmitz
Robin Schmitz

Reputation: 31

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, "(.+)\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

Answers (1)

Pablo Bernabeu
Pablo Bernabeu

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:

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

Upvotes: 4

Related Questions