# [Rd] Expected behavior from: all(c(NA, NA, NA) < NA, na.rm = TRUE)?

From: Marc Schwartz <marc_schwartz_at_comcast.net>
Date: Wed, 20 Jun 2007 10:53:25 -0500

Came across this curious behavior in:

R version 2.5.0 Patched (2007-06-05 r41831)

A simplified example is:

> all(c(NA, NA, NA) > NA, na.rm = TRUE)
 TRUE Is this expected by definition?

If one reduces this to individual comparisons, such as :

> NA > NA

 NA

> all(NA > NA)

 NA

> all(NA > NA, na.rm = TRUE)

 TRUE the initial comparison on the 3 element vector would be consistent with the last example.

If one evaluates each side of the comparison within the parens in the initial example, you get something along the lines of the following:

x <- c(NA, NA, NA)
x <- x[!is.na(x)] # remove NA's (eg. mean.default(x, na.rm = TRUE))

> x

logical(0)

> logical(0) > NA

logical(0)

This would seem appropriate, given that there is no actual comparison being made with NA, I think, since logical(0) is an 'empty' vector.

However, should all(logical(0)) return TRUE or logical(0)? For example:

> logical(0) == logical(0)

logical(0)

> all(logical(0) == logical(0))

 TRUE If the initial comparison of logical(0) returns logical(0), which is not TRUE:
> logical(0) == TRUE

logical(0)

Given a sequence of logical arguments, a logical value indicating whether or not all of the elements of x are TRUE. The value returned is TRUE if all of the values in x are TRUE, and FALSE if any of the values in x are FALSE.
If na.rm = FALSE and x consists of a mix of TRUE and NA values, the value is NA.

Thanks,

Marc Schwartz

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 20 Jun 2007 - 15:56:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Jun 2007 - 17:35:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.