Re: [R] Passing function to tapply as a string

From: Izmirlian, Grant (NIH/NCI) [E] <>
Date: Sat, 08 Mar 2008 23:16:21 -0500

>From what you've provided its nearly impossible to help you.
I think that I understand enough to provide a solution the problem that I believe you are posing.

First some comments:
(1) You can't expect that passing a character string to the argument of

     tapply that expects a function to work (2) Note that the INDEX argument of tapply must be of class 'factor' (3) From what you've provided it isn't clear where 'ttime' and 'fmt'

    are coming from, or even that they are of the same length as     dfd[,param[1]] which is neccesary in order for this to work,     but I will assume that you have a handle on that. Since they     first appear within the definition of function 'dd', then     you should most likely include them as arguments to 'dd'     unless you want to gamble on them being defined either in the     global frame or the frames ancestral to the frame of evaluation. (4) I'm willing to bet that you've been using the '...' un-named

     arguments to 'dd' in hopes that this would be a kind of magic
     bandaid..., and I'm willing to bet that you really don't need

  function(dfd,, ttime, fmt){ <- format(ttime,fmt)
    ttime.fact <- as.factor(

       param[3] = tapply(dfd[,param[1]],ttime.fact, 
                         FUN=function(x, fn.nm=param[3]){
                               .call. <-
                               .call.[[1]] <-


-----Original Message-----
From: Yuri Volchik [] Sent: Fri 3/7/2008 6:06 AM
Subject: [R] Passing function to tapply as a string  


Was wondering if it is possible to pass function name as a parameter, smth along this line<-c(1,'max','h')

dd<-function(dfd,,...){ <- format(ttime,fmt)

     param[3] = tapply(dfd[,param[1]],,param[3]),


I know there is a as.formula expression but not quite sure if there is some way to accomplish what i need.

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 09 Mar 2008 - 04:19:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 09 Mar 2008 - 07:30:21 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive