0

I have a data set for R where everything is pretty good, except what I need to be 0 to do calculations is 100 in my data set. How do I change all of the 100s in my data set to zero? Which functions do I use? I need to replace all of the 100 values in the “Grades” column with 0.

I tried to use mutate and case-when, and I just got error messages.

1 Answers1

1

In dplyr, we can use case_match or replace

df %>%
    mutate(grades = case_match(grades, 100 ~ 0, .default = grades))

df %>%
    mutate(grades = replace(grades, grades == 100, 0))
GuedesBF
  • 8,409
  • 5
  • 19
  • 37