I have the following dataset that contains id, sex, and a numeric variable, xvar.
id <- c(1,1,1,1,2,2,3,3,4,4,4,5,5)
sex <- c(1,1,1,1,2,2,2,2,1,1,1,2,2)
xvar <- c(10,11,10,12,9,9.1,10,10.4,3,2.9,4,11,11.1)
df <- data.frame(id,sex,xvar)
For each id, I want to check the min and max of xvar. If 1.05*min(xvar) >= max(xvar) then I need to keep the records. Otherwise, delete them.
For example, if id is 1, min(xvar)=10 and max(xvar)=12. Also, 1.05*10 < 12 ... then
delete the records for the id of 1.
Another example is when id is 5. So min(xvar)=11, max(xvar)=11.1, and 1.05*11 > 11.1. Keep the records where id is 5.