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

Richard A. O'Keefe ok at cs.otago.ac.nz
Fri Apr 16 02:42:08 CEST 2004


"Liaw, Andy" <andy_liaw at merck.com> 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,
	all(integer(n) == integer(n))		=> TRUE
	any(integer(n) != integer(n))		=> FALSE
Your proposal would give wrong answers for n == 0.

For any simple array (who knows what an arbitrary object will do?)
we expect all(x == x) => TRUE, any(x != x) => FALSE.  If this were
changed for empty x, we'd never be able to trust any() or all() again.

Find a book about logic and read how bounded quantification
(\forall x \in set) p(x)
(\exists x \in set) p(x)
is supposed to work when the set is empty.




More information about the R-help mailing list