[R] Tree package on R 1.4.1

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Tue Apr 23 12:16:08 CEST 2002

On Tue, 23 Apr 2002 baba at muj.biglobe.ne.jp wrote:

> Dear R-users
> I would like to apply classification and regression tree(CART) to the following data.

You can use a classification tree or a regression tree, but not a
`classification and regression tree'.  Your usage below suggests you want
a regression tree.

> I have some question on using 'tree' package.
> The data contains one response variable Y and five explanatory variables.
> The explanatory variable "x2" is categorical and not ordinal.
> But, the result obtained after running following R code
> has indicated that x2 is regard as continuous variable.

Well, that *is* what you asked for!  You read x2 as a numeric variable in
scan.  ?tree will tell you how to specify a categorical variable (via a

> I think that CART procedure can be available to categorical and continuous variables.
> How can I correct the R code such that x2 is regard as categorical and not ordinal?

Try  Ex6$x2 <- factor(Ex6$x2).

Note that the rpart package is the recommended way to perform tree-based
analyses in R, and that `CART' is a trademark of a commercial package.

> By all means, reply me your suggestion or comments.
> Thanks and best regards,
> Baba
> ----------beginning  of R code --------------------
> inputlist <- list(Y=0, x1=0, x2=0, x3=0,x4=0,x5=0)
> # inputlist <- list(Y=0, x1=0, x2="", x3=0,x4=0,x5=0)
> Ex6 <- scan("c:\\data\\CART\\EX6.txt",inputlist)
> Ex6.ltr <- tree(Y ~ x1 + x2 +x3 + x4 +x5 ,Ex6)
> ----------end of R code ---------------------------

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list