I\'m using rpart
to make a decision tree. For example:
fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
How do
Try simply passing the formula as a character string:
rpart_formula <-paste("Kyphosis ~ ",paste(predictor_variables, collapse="+"))
that should be coerced to a formula by rpart
.
Edit
As noted in the comments below, not all functions will do the coercion for you, so you should not rely on this behavior, but in this case rpart
most certainly does.
Use as.formula
:
rpart_formula <- as.formula(
paste("Kyphosis ~ ",
paste(predictor_variables, collapse = " + "),
sep = ""
)
)