[R] tests for NULL objects
Charilaos Skiadas
skiadas at hanover.edu
Thu Nov 30 06:58:04 CET 2006
On Nov 29, 2006, at 7:58 PM, Benilton Carvalho wrote:
> But that's okay, just a matter of adding an extra test (already done).
>
I'm guessing it would be something like: all(is.na(v) | v==2)
> When I asked for clarification about the reasons for this, I assumed
> that:
> if all(v) is TRUE ==> any(v) is TRUE; for all " (logical) v"...
> When actually:
> if all(v) is TRUE ==> any(v) is TRUE; for all "(logical) v of length
>> = 1".
I like to think of it as: in order for the statement "all elements of
v are TRUE" to be false, one would need to provide an element of v
which is false. Since that is not possible if v has no elements, then
the statement "all elements of v are TRUE" can't be false, hence has
to be true.
Similarly, the statement "any(v) is TRUE" translates to "there is an
element of v that is true". Since there are no elements in v, this
can't possibly happen. So this statement is false.
As for the sums and products, the explanation that Martin linked to
sums it up nicely. Basically, suppose we have two vectors, v,w, and v
is actually numeric(0). Then sum(c(v,w)) ought to be sum(v) + sum(w)
(since that would be the case for any other "honest" vectors). But
since c(v,w) is really w, the only way this will happen is if sum(v)
= 0. Same for products, since in that case prod(c(v,w))=prod(v) times
prod(w).
> Thank you,
>
> benilton
Haris
More information about the R-help
mailing list