[R] Linear Model "NA" Value Test

David Winsemius dwinsemius at comcast.net
Mon Sep 21 22:50:47 CEST 2009


On Sep 21, 2009, at 4:38 PM, Douglas M. Hultstrand wrote:

> Hello,
>
> I am deriving near real-time liner relationships based on 5-min
> precipitation data, sometimes the non-qced data result in a slope of  
> NA.  I
> am trying to read the coefficient (in this example x) to see if it  
> is equal
> to NA, if it is equal to NA assign it a value of 1.  I am having  
> trouble
> with the if statement not recognizing the coefficient or "NA" value  
> in the
> test.
>
> Any thoughts, I supplied a really basic example below.
>
> Thank you,
> Doug
>
> #####################
> ###### Example ######
> #####################
> x=c(1,1,1)
> y=c(1,1,1)
> fit <- lm(y~x) fit
>
> Call:
> lm(formula = y ~ x)
> Coefficients:
> (Intercept)            x
> 1           NA
>
> coef <- coef(fit) fit$coef[[2]]
> [1] NA
> if("fit$coef[[2]]" == "NA") {.cw = 1}
.
That would test for equality to the string composed of "N" and "A" but  
not for NA. (Nothing "equals" NA. )

?is.na


>
> -- 
> ---------------------------------
> Douglas M. Hultstrand, MS
> Senior Hydrometeorologist
> Metstat, Inc. Windsor, Colorado
> voice: 970.686.1253
> email: dmhultst at metstat.com
> web: http://www.metstat.com
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list