I would like an efficient way to replace values of many columns to NAif they are bigger than the value of a different column.
For example: replace all values in columns height1:height5 with NA if these values are >height6
set.seed(1)
# example data
N <- 200
data <- data.frame(id = 1:N,
height1 = rnorm(N,50:60),
height2 = rnorm(N,60:70),
height3 = rnorm(N,70:80),
height4 = rnorm(N,80:90),
height5 = rnorm(N,90:100),
height6 = rnorm(N,60:110))
height5is greater thanheight6, so do you want to replace all values inheight5with NA, or just the value on that row? And do you want to replace all values in the row with NA (likeheight1, height2, ..., height5) with NA? Please be more specific by giving an example, if needed.