dplyr: Replace values rowwise based on value in one variable
问题 I want to exclude participants from an analysis that are too old (age >90). Usually I would do it like that: df <- data.frame(age=c(1,10, 100), x= 1:3, y= 1:3) df[df$age > 90, ] <- NA I can't figure out how to do this with dplyr. If we want to replace one variable we can use library(dplyr) df <- data.frame(age=c(1,10, 100), x= 1:3, y= 1:3) df %>% mutate(age= replace(age, age> 90, NA)) So I thought I could use df %>% mutate_all(function(i) replace(i, age> 90, NA)) I also tried mutate_if and