Skip to content

Problem with range()

3 messages · Colin Wahl, Sarah Goslee, William Dunlap

#
Hello,
I'm using range do define boundaries for a linear model, so the line I
graph is only graphed for the range of data. There are NAs in the
data, but I dont remember this being a problem before. I typed
na.action=na.omit anyway, which has usually solved any NA issues in
the past. Any idea why R cant do vector functions for these data?
Solution?

Thanks,
Colin Wahl
M.S. Biology candidate
Western Washington University

fit<-lm(sandcomb ~ CCEC25)
z<-predict(fit, data.frame(CCEC25=range(CCEC25)))
lines(range(CCEC25), z, lty=2, lwd=0.75, col="grey51")
[1] TRUE
[1] TRUE
[1] NA NA
[1]   375.8  8769.0      NA  4197.0      NA 36880.0  4167.0 13100.0  3694.0
[10] 51420.0 30660.0 30850.0  4076.0      NA 59450.0 16050.0      NA 65480.0
[19]  2101.0 16390.0  5968.0 11330.0  9112.0  8326.0
R version 2.14.1 (2011-12-22)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] grid_2.14.1      lattice_0.20-0   lme4_0.999375-42 Matrix_1.0-2
[5] nlme_3.1-102     stats4_2.14.1    tools_2.14.1
#
Hi Colin,

You should always check the help for your function:
?range says:
     range(..., na.rm = FALSE)

Arguments:

     ...: any ?numeric? or character objects.

   na.rm: logical, indicating if ?NA?'s should be omitted.

So for example:
[1] NA NA
[1] 1 3


Sarah
On Wed, Feb 1, 2012 at 7:48 PM, Colin Wahl <biowahl at gmail.com> wrote:

  
    
#
range() is not affected by by options("na.action").  Use
the argument na.rm=TRUE.  For plotting purposes finite=TRUE
is nice, as it skips +-Inf as well.

  > range(c(NA, 1, 2, Inf))
  [1] NA NA
  > range(c(NA, 1, 2, Inf), na.rm=TRUE)
  [1]   1 Inf
  > range(c(NA, 1, 2, Inf), finite=TRUE)
  [1] 1 2

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com