[R] tests for NULL objects
Martin Morgan
mtmorgan at fhcrc.org
Thu Nov 30 01:54:14 CET 2006
Bert Gunter <gunter.berton at gene.com> writes:
> Merely convention.
There's a similar thread in the R-devel newgroup about
'prod(numeric(0)) surprise' started by Ben Bolker, 09 Jan 2006,
(https://stat.ethz.ch/pipermail/r-devel/2006-January/036041.html) and
the post by Andy Liaw
(https://stat.ethz.ch/pipermail/r-devel/2006-January/036057.html)
proved particularly helpful to me (mathematical reasons, in addition
to convention):
> From: Liaw, Andy <andy_liaw_at_merck.com>
> Date: Mon 09 Jan 2006 - 18:27:41 GMT
> If you haven't seen this in your math courses, perhaps this would help:
> http://en.wikipedia.org/wiki/Empty_set
> which says, in part:
> Operations on the empty set
> Operations performed on the empty set (as a set of things to be
> operated upon) can also be confusing. (Such operations are nullary
> operations.) For example, the sum of the elements of the empty set
> is zero, but the product of the elements of the empty set is one
> (see empty product). This may seem odd, since there are no elements
> of the empty set, so how could it matter whether they are added or
> multiplied (since "they" do not exist)? Ultimately, the results of
> these operations say more about the operation in question than about
> the empty set. For instance, notice that zero is the identity
> element for addition, and one is the identity element for
> multiplication.
> Andy
'any' is like 'sum', 'all' is like 'prod'.
Martin
> NULL == 2 <==> logical(0), that is, a logical vector of length 0. It makes
> sense (at least to me) that any(logical(0)) is FALSE, since no elements of
> the vector are TRUE. all(logical(0)) is TRUE since no elements of the vector
> are FALSE.
>
> I think these are reasonable and fairly standard conventions, but even if
> you disagree, they are certainly not worth making a fuss over and certainly
> cannot be changed without breaking a lot of code, I'm sure.
>
> Bert Gunter
> Nonclinical Statistics
> 7-7374
>
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Benilton Carvalho
> Sent: Wednesday, November 29, 2006 2:21 PM
> To: R-Mailingliste
> Subject: [R] tests for NULL objects
>
> Hi Everyone,
>
> After searching the subject and not being successful, I was wondering
> if any you could explain me the idea behind the following fact:
>
> all(NULL == 2) ## TRUE
> any(NULL == 2) ## FALSE
>
> Thanks a lot,
>
> Benilton
>
> --
> Benilton Carvalho
> PhD Candidate
> Department of Biostatistics
> Johns Hopkins University
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
--
Martin T. Morgan
Bioconductor / Computational Biology
http://bioconductor.org
More information about the R-help
mailing list