The function %>% mutate is not recognised

I am trying to aggrupate the categories of my variables. For some reason the function rather gives error:

Error in `mutate()`:
ℹ In argument: `across(...)`.
Caused by error in `across()`:
ℹ In argument: `all_of(Nivell_Educatiu_Mare)`.
Caused by error:
! objeto 'Nivell_Educatiu_Mare' no encontrado
Run `rlang::last_trace()` to see where the error occurred.

Rather doesn't read it as a function:

> dadespares_netes <- dadespares_netes %>%
+     Nivell_Educatiu_Pare == "No sap llegir ni escriure" ~ "Primària incompleta",
Error: inesperado ',' in:
"dadespares_netes <- dadespares_netes %>%
    Nivell_Educatiu_Pare == "No sap llegir ni escriure" ~ "Primària incompleta","
>     Nivell_Educatiu_Pare == "Primera etapa de secundària" ~ "ESO",
Error: inesperado ',' en "    Nivell_Educatiu_Pare == "Primera etapa de secundària" ~ "ESO","
>     Nivell_Educatiu_Pare == "Universitaris de grau superior" ~ "Universitaris",
Error: inesperado ',' en "    Nivell_Educatiu_Pare == "Universitaris de grau superior" ~ "Universitaris","
>     TRUE ~ Nivell_Educatiu_Pare  # retain original value if no match

The code was working before, I used it in another project, and I actually changed some category names in this project with the same codes. All of a sudden, it stopped working.
The data frame is loaded and read, dplyr too, the names of the variables and categories are correct too...

I have been trying to solve it for already an hour, and not even reestarting the program and the computer I made it work. I tried with recode, and case when()

Any chance that

library(magrittr)

is missing?

The code above doesn't make sense to me. You are passing dadespares_netes into Nivell_Educatiu_Pare but Nivell_Educatiu_Pare isn't a function. Simultaneously, you are setting up a bare formula with Nivell_Educatiu_Pare == "No sap llegir ni escriure" ~ "Primària incompleta". Pleases show . Please show more of your code, not just the parts that throw an error.

The unexpected comma error in your second code chunk is because the pipe operator is expecting a function (into whose first argument dadespares_netes will be substituted) but instead finding a logic expression (Nivell_Educatiu_Pare is equal to "No sap llegir ni escriure" ~ "Primària incompleta"). It is not clear what part of your code is supposed to be a function.

Could you post both the part of the original code that you decided to change, and the revised code that includes your changes?

Are you sure that run this object before code? Remember load all the object and libraries.

library(tidyverse)
# load file
Nivell_Educatiu_Mare 

In this other box, you try do a when_case?

dadespares_netes <- data.frame(
  Nivell_Educatiu_Pare = c("No sap llegir ni escriure", "Primera etapa de secundària", "Universitaris de grau superior", "Altres"))

# case_when 
dadespares_netes <- dadespares_netes %>%
  mutate(
    Nivell_Educatiu_Pare_Transformado = case_when(
      Nivell_Educatiu_Pare == "No sap llegir ni escriure" ~ "Primària incompleta",
      Nivell_Educatiu_Pare == "Primera etapa de secundària" ~ "ESO",
      Nivell_Educatiu_Pare == "Universitaris de grau superior" ~ "Universitaris",
      TRUE ~ Nivell_Educatiu_Pare ))

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.