Probably easy question (hopefully not duplicate, no idea how to phrase it) - how to update multiple questions in R at the same time with various outputs if they would alter the initial filter?
An abstract example:
id_code <- sample(1:1000,20)
age <- sample(40:80,20, replace=T)
heart_disease <- sample(0:1,20,replace=T)
weight <- sample(105:250,20,replace=T)
dat <- data.frame(id_code,age,heart_disease,weight)
dat <- dat[dat$age > 50 & dat$heart_disease ==1, ] #???
Looking at this case I would like to change in this example let's say age to 50 and heart_disease to 0 (but only the records that age is > 50 and hd = 1). If I do it iteratively, after the first operation the filter will no longer yield the same records - how can I update it in one go?
The expected output is how can I transform dat that is filtered if the operation would affect filter and requires 2 steps (as explained in the paragraph above)