Replace NA's in Predictor Variables

DESCRIPTION:
Adds a new level called "NA" to any discrete predictor in a data frame that contains NAs. na.tree.replace stops if any continuous (numeric) predictor contains an NA. na.tree.replace.all will quantize numeric predictors and create a factor with a level for the missing values.

USAGE:
na.tree.replace(frame)
na.tree.replace.all(frame)

REQUIRED ARGUMENTS:
frame:
data frame used to grow a tree.

VALUE:
data frame such that a new level named "NA" is added to any discrete predictor in frame with NAs. In the case of na.tree.replace.all, all predictors having NAs are changed in an analogous manner.

DETAILS:
This function is used via the na.action argument to tree.

SEE ALSO:
tree , na.omit , na.fail

WARNING:
The use of na.tree.replace.all for continuous variables with missing values might be risky. These continuous predictors are replaced by factors based on their quartiles. This migh be a good exploratory step but it raises a problem if used in predictions. If the variable has missing values in only one of the fitted or the new datasets, the values used may turn out completely incompatible (factor vs. numeric).

EXAMPLES:
z <- tree(market.survey, na.action=na.tree.replace)