Skip to content

paste dependent variable in formula (rpart)?

3 messages · Uwe Ligges, Christian Schulz

#
Hello,

i'm trying to replace  different  target variables in rpart with a 
function. The data.frame getting always the target variable as last column.
Try below, i get the target variable in the explained variables, too!?  
Have anybody an advice to avoid this.

rp1 <- rpart(eval(parse(text=paste(names(train[length(train)])))) ~ . , 
data=train,cp=0.0001)

regards & many thanks
Christian
#
Christian Schulz wrote:
I guess you want something along the following example:

   train <- iris
   form <- as.formula(paste(names(train)[length(train)], "~ ."))
   rpart(form, data = iris)

or some data.frame method for rpart....

Uwe Ligges
#
yes ,many thanks!
Christian