Hello all, I wish to extract the terms from an rpart object. Specifically, I would like to be able to know what is the response variable (so I could do some manipulation on it). But in general, such a method for rpart will also need to handle a "." case (see fit2) Here are two simple examples: fit1 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis) fit1$call fit2 <- rpart(Kyphosis ~ ., data=kyphosis) fit2$call Is there anything "prettier" then using string manipulation? Thanks. ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]]
Try this: all.vars(terms(fit1)) all.vars(terms(fit2)) On Wed, Jan 26, 2011 at 3:33 PM, Tal Galili <tal.galili@gmail.com> wrote:> Hello all, > > I wish to extract the terms from an rpart object. > Specifically, I would like to be able to know what is the response variable > (so I could do some manipulation on it). > But in general, such a method for rpart will also need to handle a "." case > (see fit2) > > Here are two simple examples: > > fit1 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis) > fit1$call > fit2 <- rpart(Kyphosis ~ ., data=kyphosis) > fit2$call > > > Is there anything "prettier" then using string manipulation? > > > Thanks. > > > > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili@gmail.com | 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > > ---------------------------------------------------------------------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Take a look at the output of terms(fit2) In particular tm <- terms(fit2) attr(tm, "response") is 1 if there is a response and variables <- as.list(attr(tm, "variables"))[-1] variables[[1]] gives the response expression if there is one. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Tal Galili > Sent: Wednesday, January 26, 2011 9:33 AM > To: r-help at r-project.org > Subject: [R] Extracting the terms from an rpart object > > Hello all, > > I wish to extract the terms from an rpart object. > Specifically, I would like to be able to know what is the > response variable > (so I could do some manipulation on it). > But in general, such a method for rpart will also need to > handle a "." case > (see fit2) > > Here are two simple examples: > > fit1 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis) > fit1$call > fit2 <- rpart(Kyphosis ~ ., data=kyphosis) > fit2$call > > > Is there anything "prettier" then using string manipulation? > > > Thanks. > > > > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili at gmail.com | 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il > (Hebrew) | > www.r-statistics.com (English) > -------------------------------------------------------------- > -------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Maybe Matching Threads
- enableJIT(2) causes major slow-up in rpart
- Is there an equivalence of lm's “anova” for an rpart object ?
- Large file size while persisting rpart model to disk
- rpart - how to estimate the “meaningful” predictors for an outcome (in classification trees)
- RPART - printing full splitting rule number on tree plot