[R] Problem with range()

William Dunlap wdunlap at tibco.com
Thu Feb 2 03:26:13 CET 2012


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 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Colin Wahl
> Sent: Wednesday, February 01, 2012 4:48 PM
> To: r-help at r-project.org
> Subject: [R] Problem with range()
> 
> 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")
> 
> 
> > is.vector(CCEC25)
> [1] TRUE
> 
> > is.numeric(CCEC25)
> [1] TRUE
> 
> > range(CCEC25)
> [1] NA NA
> 
> > CCEC25
>  [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
> 
> > sessionInfo()
> 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
> 
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list