[R] Using objectname in function

Gabor Grothendieck ggrothendieck at gmail.com
Wed Aug 18 13:36:58 CEST 2010


On Wed, Aug 18, 2010 at 7:23 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Wed, Aug 18, 2010 at 7:10 AM, JesperHybel <jesperhybel at hotmail.com> wrote:
>>
>> Is there anyway I can convert a vectors objectname to a string to be used in
>> fx:
>>
>> Monkey<-c(0,0,0,1,1,1)
>> Wax<-c(1,0,1,0,1,0)
>>
>> f<-function(x,y){ table(x,y) }
>>
>> f(Monkey,Wax)
>>
>> so that the printout is not
>>
>>   y
>> x   0 1
>>  0 1 2
>>  1 2 1
>>
>> but
>>
>>          Wax
>> Monkey 0 1
>>        0 1 2
>>        1 2 1
>>
>
> Try this:
>
>  f <- function(...) eval.parent(substitute(table(...)))
>

Actually this would be good enough:

   f <- function(...) table(...)

or even

   f <- table



More information about the R-help mailing list