Skip to content
Prev 345541 / 398502 Next

range () does not remove NA's with complete.cases() for dates (dplyr/mutate)

This may not be mutate()'s problem.

The Date class is messed up with regard to NA's and Inf's.  E.g., what gets
printed as NA does not correspond to what is.na() returns and its range()
method does not appear to pass the finite=TRUE argument to range.default:
  > d <- as.Date(c("2014-10-31", c("2014-11-10")))
  > d1 <- range(d[0], finite=TRUE)
  Warning messages:
  1: In min.default(numeric(0), na.rm = FALSE) :
    no non-missing arguments to min; returning Inf
  2: In max.default(numeric(0), na.rm = FALSE) :
    no non-missing arguments to max; returning -Inf
  > d1
  [1] NA NA
  > is.na(d1)
  [1] FALSE FALSE
  > dput(d1)
  structure(c(Inf, -Inf), class = "Date")
  > range(c(d1, d), finite=TRUE)
  [1] NA NA
  > range(c(d1, d), finite=TRUE, na.rm=TRUE)
  [1] NA NA



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Nov 10, 2014 at 10:09 AM, Muhuri, Pradip (SAMHSA/CBHSQ) <
Pradip.Muhuri at samhsa.hhs.gov> wrote: