[R] Passing values to a function when using apply

Abhishek Pratap abhishek.vit at gmail.com
Tue Apr 27 21:29:10 CEST 2010

Hi Guys

Thank you for clearing something I dint know. Just wondering the
reason of putting the word function(x)  in the apply function when we
have already declared stats function separately.

I better understand how the arguments are passed.


On Tue, Apr 27, 2010 at 2:46 PM, Erik Iverson <eriki at ccbr.umn.edu> wrote:
> Henrique Dallazuanna wrote:
>> try this:
>> apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1,
>> function(x)stats(x[1], x[2], total=55000000))
> I agree with this, that was my point in my original reply.  Apply is *not*
> passing 2 arguments simply because you are selecting two columns of the
> input object, it's passing *one argument*, which is the *entire row* of the
> input object.  You can then access them individually within the stats
> function, as Henrique shows.

More information about the R-help mailing list