I have a dataset where I'm trying to change the values of some variables based on a different variable with an if else statement. However, I only want to change the variable if a certain condition is met - otherwise I want the variable to be unchanged. How do I do this in dplyr?
e.g., if I have 4 sites (a, b, c and d), that are each associated with a value of 10, 20, 30 and 40, respectively, and I just want to change the value of 10 at site a to 12.
df2 <- df %>%
mutate(lat = ifelse(site == "a", 12, WHAT GOES HERE?))
df2 <- df %>%
mutate(lat = ifelse(site == "a", 12, lat))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With