I'm trying to create a new variable that contains the substitution of where "NA" is in the Var1 variable by 0 and leave the other observations as they normally are, using a mutate function from the dplyr package. However, I am not getting what I wanted.
Below are the data and codes:
Dados1 <- data.frame(Var1 = c(rep("NA", 4), "H", "Q",rep("NA", 4)))
Dados1
library(dplyr)
Dados1 <- Dados1 %>%
dplyr::mutate(NewCode = ifelse(Var1 == "NA", "0"))
Dados1
Erro: Problem with `mutate()` input `NewCode`.
x argumento "no" ausente, sem padrĂ£o
i Input `NewCode` is `ifelse(Var1 == "NA", "0")`.
Run `rlang::last_error()` to see where the error occurred.
> Dados1