Skip to content
Prev 277304 / 398506 Next

help in fitted values in lm function

If you want fitted() to return NAs in the positions where
there were NA's in data, use na.action=na.exclude in your
call to lm().  E.g.,

  > z <- data.frame(y=1:5, x=c(1,NA,3,3,5))
  > fitted(lm(y~x, data=z))
     1    3    4    5 
  1.25 3.25 3.25 5.25 
  > fitted(lm(y~x, data=z, na.action=na.exclude))
     1    2    3    4    5 
  1.25   NA 3.25 3.25 5.25

I think the help file for model.matrix has more detail,
including how to use options() to set the na.action for
your R session.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com