[R] variable names
Hotz, T.
th50 at leicester.ac.uk
Tue Jul 22 16:07:10 CEST 2003
Dear Luis,
You might want to have a look at
"Bill Venables. Programmer's niche. R News, 2(2):24-26, June 2002"
which you can find at http://cran.r-project.org/doc/Rnews/
or look into the manual "R Language Definition", chapter
"Computing on the language".
Assuming that in your case the variable to be classified is called
classLabels, and the names of your datasets are in a vector called
dataNames, you could use something like
lapply(dataNames,function(theName){
eval(parse(text = paste("rpart(classLabels~., data =", theName, ")")))
})
which will return a list of results. This is achieved by generating the
command line you would type as a string using paste, which is then parsed
and explicitly evaluated.
See the corresponding help pages for more details.
HTH
Thomas
---
Thomas Hotz
Research Associate in Medical Statistics
University of Leicester
United Kingdom
Department of Epidemiology and Public Health
22-28 Princess Road West
Leicester
LE1 6TP
Tel +44 116 252-5410
Fax +44 116 252-5423
Division of Medicine for the Elderly
Department of Medicine
The Glenfield Hospital
Leicester
LE3 9QP
Tel +44 116 256-3643
Fax +44 116 232-2976
> -----Original Message-----
> From: Luis Miguel Almeida da Silva [mailto:lsilva at fc.up.pt]
> Sent: 22 July 2003 14:49
> To: r-help at stat.math.ethz.ch
> Subject: [R] variable names
>
>
> 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
>
> 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