Mutating multiple columns dynamically while conditioning on specific rows
问题 I know there are several similar questions around here, but none of them seems to address the precise issue I'm having. set.seed(4) df = data.frame( Key = c("A", "B", "A", "D", "A"), Val1 = rnorm(5), Val2 = runif(5), Val3 = 1:5 ) I want to zeroise values of the value columns for the rows where Key == "A" The column names are referenced through a grep : cols = grep("Val", names(df), value = TRUE) Normally to achieve what I want in this case I would use data.table like this: library(data.table)