Re: [R] applying a function over an array

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 19 May 2005 - 00:26:18 EST

On 5/18/05, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> On 5/18/05, BJ <erithid@bellsouth.net> wrote:
> > Is there a way to apply a function with several arguements over an
> > array? For instance if you had a function d<-function(a,b,c) {a+b+c} and
> > a 4,3 array, could you apply the function over each line of the array?
> > tapply seems to only allow one argument, and I just can't think of a way
> > to explicitly tell R that I am passing it 3 distinct objects instead of
> > 1 complex one. Thank you as always for your help. ~Erithid
>
> If x is the 4x3 array:
>
> mapply(d, x[,1], x[,2], x[,3])
>

Also you might check if your d is vectorized already (it is in your example) in which case you can just do:

   d(x[,1], x[,2], x[,3])



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu May 19 00:48:37 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:50 EST