Re: [R] all(logical(0)) and any(logical(0))

2004-04-15 Thread Rolf Turner
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

RE: [R] all(logical(0)) and any(logical(0))

2004-04-15 Thread Liaw, Andy
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

Re: [R] all(logical(0)) and any(logical(0))

2004-04-15 Thread Thomas Lumley
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

Re: [R] all(logical(0)) and any(logical(0))

2004-04-15 Thread Duncan Murdoch
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.

Re: [R] all(logical(0)) and any(logical(0))

2004-04-15 Thread Douglas Bates
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

RE: [R] all(logical(0)) and any(logical(0))

2004-04-15 Thread Liaw, Andy
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)

Re: [R] all(logical(0)) and any(logical(0))

2004-04-15 Thread Patrick Burns
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

Re: [R] all(logical(0)) and any(logical(0))

2004-04-15 Thread Richard A. O'Keefe
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,