R

Asked • 10/04/19

Change value of variable with dplyr?

I regularly need to change the values of a variable based on the values on a different variable, like this: mtcars$mpg[mtcars$cyl == 4] <- NAI tried doing this with `dplyr` but failed miserably: mtcars %>% mutate(mpg = mpg == NA[cyl == 4]) %>% as.data.frame()How could I do this with `dplyr`?

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.