[R] all(logical(0)) and any(logical(0))
Patrick Burns
pburns at pburns.seanet.com
Thu Apr 15 20:20:09 CEST 2004
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 of any
specific instances at the moment.
Patrick Burns
Burns Statistics
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
Douglas Bates wrote:
>"Liaw, Andy" <andy_liaw at merck.com> 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
>>
>>
>>>sum(numeric(0))
>>>
>>>
>>[1] 0
>>
>>but why?
>>
>>
>
>The operation applied to a zero-length vector returns the identity
>element of the operator. The identity element of * is 1, of + is 0,
>of & is TRUE and of | is FALSE.
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>
>
More information about the R-help
mailing list