I'm currently working through Programming with R, and I can't seem to make my "if" function work on a vector with length > 1. The book says to use the "any" function as "if" has to evaluate a single TRUE or FALSE.
I have written:
num<-c(-2,-1,0,1,2)
if(any(num<0)){num<-num*-1}
num
[1] 2 1 0 -1 -2
Can anyone help point out my mistake?
Thanks!