[R] can predict ignore rows with insufficient info

Peter Whiting pete at sprint.net
Tue Sep 16 21:15:34 CEST 2003


On Tue, Sep 16, 2003 at 11:44:02AM -0500, Peter Whiting wrote:
> 
> I'm not sure how to identify the cities in nconst that are not
> modeled by g (my actual model has many more predictors in the
> formula)

I guess I could use some form of
subset(const,const$city%in%g$xlevels$city) 
over and over again for each factor...

as usual, there has to be a better way.

pete




> Is there a way to instruct predict to only predict the
> rows for which it has enough information and not complain about
> the others?
> 
> g<-lm(days~city,data=const)
> x<-predict(g,nconst) ## the rows of x with city=ALBANY will be NA
> g<-lm(days~state,data=const)
> y<-predict(g,nconst)
> x[is.na(x)]<-y[is.na(x)]
> 
> thanks,
> pete
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list