Re: [R] 'all' inconsistent?

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 31 Jan 2006 - 03:21:51 EST

Seth Falcon <sfalcon@fhcrc.org> writes:

> On 30 Jan 2006, ligges@statistik.uni-dortmund.de wrote:
> > Current behaviour is consistent in so far that identical(all(x),
> > !any(!x)) is TRUE and definition of any() is obvious.
>
> That helps, thanks. I'm not sure I've had enough coffee to continue,
> but, for the set analogy I think we are saying:
>
> logical(0) is the empty set {}.
> Complement of {} is the universal set U.
>
> Then !logical(0) == !{} == U. any(U) is TRUE, isn't it?
>
> I guess the real message is that you need to protect yourself by
> testing for positive length first.

This comes up repeatedly. Probably the most useful way of viewing these empty sum/prod/any/all issues is that you want

sum(c(x,y)) == sum(x) + sum(y)
prod(c(x,y)) == prod(x) * prod(y)
any(c(x,y)) == any(x) | any(y)
all(c(x,y)) == all(x) & all(y)

even in the cases where x or y is empty, and of course the neutral operations are

adding 0
multiplying by 1
or'ing with FALSE
and'ing with TRUE

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Jan 31 03:30:42 2006

This archive was generated by hypermail 2.1.8 : Tue 31 Jan 2006 - 08:22:20 EST