[R] Passing values to a function when using apply

Erik Iverson eriki at ccbr.umn.edu
Tue Apr 27 20:46:03 CEST 2010



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