Re: [R] paste dependent variable in formula (rpart)?

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Mon, 17 Dec 2007 00:26:45 +0100

Christian Schulz wrote:
> 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)])))) ~ . ,

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

> data=train,cp=0.0001)
>
> regards & many thanks
> Christian
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 16 Dec 2007 - 23:32:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Dec 2007 - 10:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.