How (and can) I use different operators on command in if and else function?
x <- as.numeric(c(1,1,4,5,6,7,8))
if(mean(x) < 3){operator.is <- <}else{operator.is <- >}
sub <- subset(x, x operator.is 2)
#expected results
sub
[1] 3 4 5 6 7 8
I want to store the operator in "operator.is", based on the if statement. Yet, I do not seem to be able to store an operator and use it in the subset function. Later in want to use this operator to subset. Without this I will need to copy and past the whole code just to use the other operator. Is there any elegant and simple way to solve this?
Thanks in advance