[R] Passing values to a function when using apply

Erik Iverson eriki at ccbr.umn.edu
Tue Apr 27 20:16:55 CEST 2010

This is not a reproducible example. You might simply want:

apply(veh_drg_animal1[, c("readCount", "gene_length")], 1, stats, arg2, 

But your "two parameters" from the data.frame are really going to be 
passed as one vector, and then within the stats function you can access 
them individually.  I'm guessing you really want a 2-parameter stats 
function call, but it's hard to tell without a real example.

Abhishek Pratap wrote:
> Hi All
> Slightly lost on how should I pass values to a function I am calling
> using apply.
> apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1,  stats() )
> here stats is a custom function where I want to pass two parameters
> from data frame as shown and a third argument which is constant per
> instance of apply.
> stats <- function ( arg1,agr2,agr3) {
> ## computation using three parameters
> }
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list