[R] Can I replace NA by 0 (if yes, how) ?

Ptit_Bleu ptit_bleu at yahoo.fr
Wed Nov 7 17:00:32 CET 2007


Hello,

I'm trying to fit some points with a 8-degrees polynom (result of lm is
stored in pfit).
In most of the case, it is ok but for some others, some coefficients are
"NA".
I don't really understand the meaning of these "NA".

And the problem is that I can't perform a derivation
(pderiv<-as.function((deriv(polynomial(pfit$coefficients))))) on pfit due to
the presence of these "NA".

I tried the functions na.omit and na.exclude but "NA" are still there.
I tried to replace manually "NA" by 0. The fit seems ok and then I can
derive the polynom.

But can I do this and, if yes, how can I detect and automatically replace
these "NA" ?

To conclude, I must say that I read some posts on NA but I must confess that
it is still not clear to me (maybe because I'm french and R-newbie ...)

Thanks in advance for your help,
Ptit Bleu.


pfit

Call:
lm(formula = pfitmax ~ poly(vfitmax, 8, raw = T))

Coefficients:
               (Intercept)  poly(vfitmax, 8, raw = T)1  poly(vfitmax, 8, raw
= T)2  poly(vfitmax, 8, raw = T)3  poly(vfitmax, 8, raw = T)4  
                -2.790e+04                   6.276e+03                 
-5.645e+02                   2.591e+01                  -6.241e-01  
poly(vfitmax, 8, raw = T)5  poly(vfitmax, 8, raw = T)6  poly(vfitmax, 8, raw
= T)7  poly(vfitmax, 8, raw = T)8  
                 6.681e-03                          NA                 
-3.942e-07                          NA  


>pderiv<-as.function((deriv(polynomial(pfit$coefficients))))
Erreur dans while ((la <- length(a)) > 1 && a[la] == 0) a <- a[-la] : 
        valeur manquante là où TRUE / FALSE est requis

-- 
View this message in context: http://www.nabble.com/Can-I-replace-NA-by-0-%28if-yes%2C-how%29---tf4765597.html#a13629975
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list