Skip to content

unusual result with "any"

2 messages · Erin Hodgess, Johannes Hüsing

#
Dear R People:

I am working with a numeric vector and trying to use the "any"
function.  However, I'm getting some odd results, as shown below:
[1] 0.7305081 2.4224211
num [1:2] 0.73 2.42
[1] FALSE
Warning message:
In any(xy) : coercing argument of type 'double' to logical
What am I doing wrong please?

Thanks in advance,
Sincerely,
Erin
#
Erin Hodgess schrieb:
xy > 1 should return TRUE FALSE, and you want to apply any() to that. 
Thus: any(xy > 1)
any(xy) returns TRUE, as the nonzero numbers are coerced to TRUE
When TRUE is compared with 1, it is coerced to a number (no warning is 
issued here), namely 1.
1 > 1 returns FALSE.