Reading rpart Input Parameters from a Text Variable

前端 未结 2 1024
自闭症患者
自闭症患者 2021-01-20 14:03

I\'m using rpart to make a decision tree. For example:

fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)

How do

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 14:27

    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.

提交回复
热议问题