I'm looking to find a simple way to do something like the following but with dplyr, essentially just replacing the values in 3 columns with NA when the condition is met.
dta[dta$na.ind == 1, c('x1', 'x2', 'x3')] <- NA
The only method I can think of using dplyr is the following, but I feel there should be a simpler way
dta <- dta %>%
mutate(x1 = ifelse(na.ind == 1, NA, x1),
x2 = ifelse(na.ind == 1, NA, x2),
x3 = ifelse(na.ind == 1, NA, x3))
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…