if not conditions in R?
Try:
if(!condition) { do something }
The problem is in how you are defining the condition. It should be
if(!(x > 0)){
instead of
if(!x > 0){
This is because !x
converts the input (a numeric) to a logical - which will give TRUE
for all values except zero. So:
> fun <- function(x){
+ if (!(x > 0)) {print ("not bigger than zero")}
+ }
> fun(1)
> fun(0)
[1] "not bigger than zero"
> fun(-1)
[1] "not bigger than zero"