Hello,
applying a function to a list of variables I face the following problem:
Let's say I want to compute tables for several variables. I could write a
command for every single table, like
bravo<-c(1,1,2,3,5,5,5,);charly<-c(7,7,4,4,2,1)
table(bravo); table(charly)
> table(bravo); table(charly)
b
riginal Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Heinz Tuechler
Sent: Tuesday, February 08, 2005 11:45 AM
To: r-help@stat.math.ethz.ch
Subject: [R] How to get variable names in a function?
Hello,
applying a function to a list of variables I face the following pro
This might be easier for your purpose:
> lapply(list(bravo=bravo, charly=charly), table)
$bravo
1 2 3 5
2 1 1 3
$charly
1 2 4 7
1 1 2 2
Andy
> From: Heinz Tuechler
>
> Hello,
>
> applying a function to a list of variables I face the
> following problem:
> Let's say I want to compute t
e business of the statistician is to catalyze the scientific learning
process." - George E. P. Box
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Heinz Tuechler
> Sent: Tuesday, February 08, 2005 8:45 AM
> To: r-help@stat.math.ethz.
At 12:51 08.02.2005 -0500, Liaw, Andy wrote:
>This might be easier for your purpose:
>
>> lapply(list(bravo=bravo, charly=charly), table)
>$bravo
>
>1 2 3 5
>2 1 1 3
>
>$charly
>
>1 2 4 7
>1 1 2 2
>
>Andy
>
Thank you for your answer. In the case of the example it is sufficient, but
I see that I
mple list without
retyping each name.
Thanks again,
Heinz
>
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Heinz Tuechler
>> Sent: Tuesday, February 08, 2005 8:45 AM
>> To: r-help@stat.math.ethz.ch
>> Subj
riables to the function. By this method I can then
> access each
> variable by its index and also its name via the vector of the
> stored names.
> It seemed to me a crude method of a beginner like me and I
> still hope to
> find a better one.
> Your suggestion with the named list m
ot
>> solve it either.
>> A third way worked, but seemed to me less generally applicable.
>> I stored all the names of the variables of a data.frame in a
>> vector, made
>> the selection of the variables by match() and passed the
>> indices of the
>> selected var