[R] Rpart -- using predict() when missing data is present?

Ajay Narottam Shah ajayshah at mayin.org
Sat Oct 8 18:38:49 CEST 2005


I am doing

> library(rpart)
> m <- rpart("y ~ x", D[insample,])
> D[outsample,]
            y           x
8  0.78391922 0.579025591
9  0.06629211          NA
10         NA 0.001593063
>   p <- predict(m, newdata=D[9,])
Error in model.frame(formula, rownames, variables, varnames, extras, extranames,  : 
	invalid result from na.action

How do I persuade him to give me NA since x is NA?

I looked at ?predict.rpart but didn't find any mention about NAs.

(In this problem, I can easily do it manually, but this is a part of
something bigger where I want him to be able to gracefully handle
prediction requests involving NA).

-- 
Ajay Shah                                                   Consultant
ajayshah at mayin.org                      Department of Economic Affairs
http://www.mayin.org/ajayshah           Ministry of Finance, New Delhi




More information about the R-help mailing list