[R] variable names

Torsten Hothorn hothorn at ci.tuwien.ac.at
Tue Jul 22 15:57:31 CEST 2003


On Tue, 22 Jul 2003, Luis Miguel Almeida da Silva wrote:

> Dear helpers
>  
> I want to use rpart several times in a loop to build a classification tree. My problem is that rpart needs a formula as argument and for that the variables need to have names and this doesn't happen in my case. Every iteration in the loop has a different dataset with several variables (ex. 38 or more) and so I can't type the names by hand every time. Is there any function that generates names for variables in a dataframe. If so, how can I use then the argument
>  

If your data is organised in a data.frame, (dummy) variable names are
available by default:

R> mydata <- data.frame(matrix(rnorm(25), ncol=5))
R> mydata
          X1          X2         X3         X4          X5
1  1.3806313 -0.41827136  0.9591628 -1.3351038  0.02746110
2  0.5114590 -1.34111439 -0.9617552 -0.8367088 -0.06913021
3 -1.7508089 -0.49387076 -1.7597395  2.3899490 -0.15209650
4 -1.6753809 -1.28381808 -1.0424903  0.1002998  0.27784949
5 -0.2605535 -0.09035652 -2.5786418  1.0483400 -0.70445615
R> rpart(X1 ~ ., data = mydata)
n= 5 

node), split, n, deviance, yval
      * denotes terminal node

1) root 5 7.463698 -0.3589306 *

best,

Torsten

> rpart(classlabels~. ,.....)
>  
> thanks
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
>




More information about the R-help mailing list