Andy Liaw wrote:
I was bitten by the behavior of all() when given logical(0): It is
TRUE! (And any(logical(0)) is FALSE.) Wouldn't it be better to
return logical(0) in both cases?
It seems to me that what R does is strictly speaking correct.
Anything you say about the members of the empty
I wrote:
I was bitten by the behavior of all() when given logical(0):
It is TRUE!
(And any(logical(0)) is FALSE.) Wouldn't it be better to
return logical(0)
in both cases?
I guess the behavior is consistent with:
prod(numeric(0))
[1] 1
sum(numeric(0))
[1] 0
but why?
Andy
On Thu, 15 Apr 2004, Liaw, Andy wrote:
Dear R-help,
I was bitten by the behavior of all() when given logical(0): It is TRUE!
(And any(logical(0)) is FALSE.) Wouldn't it be better to return logical(0)
in both cases?
No, it wouldn't. The convention that For all x in A: P(x) is true
On Thu, 15 Apr 2004 10:40:41 -0400, Liaw, Andy [EMAIL PROTECTED]
wrote :
Dear R-help,
I was bitten by the behavior of all() when given logical(0): It is TRUE!
(And any(logical(0)) is FALSE.) Wouldn't it be better to return logical(0)
in both cases?
As Rolf said, this behaviour makes sense.
Liaw, Andy [EMAIL PROTECTED] writes:
I wrote:
I was bitten by the behavior of all() when given logical(0):
It is TRUE!
(And any(logical(0)) is FALSE.) Wouldn't it be better to
return logical(0)
in both cases?
I guess the behavior is consistent with:
prod(numeric(0))
[1] 1
Thanks to Rolf, Thomas, Duncan Doug for the explanations! It's one of
those things that I should have remembered from high school but clearly
didn't...
I've changed my code to:
[If y is factor:]
if (!is.null(ytest)) {
if (!is.factor(ytest)) stop(ytest must be a factor)
I suspect that some people still might not have caught why
the behavior is a good thing.
We want
any(c(A, B))
to give the same answer as
any(A) || any(B)
This should be the behavior even if all of the elements are
in one of the vectors.
This actually is useful in coding, though I can't think
Liaw, Andy [EMAIL PROTECTED] wrote:
I was bitten by the behavior of all() when given logical(0): It
is TRUE! (And any(logical(0)) is FALSE.) Wouldn't it be better
to return logical(0) in both cases?
It would be disastrous. For all integer n = 0,