Re: [R] Passing values to a function when using apply

2010-04-27 Thread Abhishek Pratap
Makes sense. Thanks guys for your quick reverts! -Abhi On Tue, Apr 27, 2010 at 3:34 PM, Erik Iverson wrote: > > > Abhishek Pratap wrote: >> >> 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 >

Re: [R] Passing values to a function when using apply

2010-04-27 Thread Erik Iverson
Abhishek Pratap wrote: 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. Thanks! -Abhi That's cre

Re: [R] Passing values to a function when using apply

2010-04-27 Thread Abhishek Pratap
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. Thanks! -Abhi On Tue, Apr 27, 2010 at 2:46 PM, Erik I

Re: [R] Passing values to a function when using apply

2010-04-27 Thread Erik Iverson
Henrique Dallazuanna wrote: try this: apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1, function(x)stats(x[1], x[2], total=5500)) 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

Re: [R] Passing values to a function when using apply

2010-04-27 Thread Henrique Dallazuanna
try this: apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1, function(x)stats(x[1], x[2], total=5500)) On Tue, Apr 27, 2010 at 3:24 PM, Abhishek Pratap wrote: > Hi Henrique and Erik > > I still get a error. See below. > > apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1, sta

Re: [R] Passing values to a function when using apply

2010-04-27 Thread Abhishek Pratap
Hi Henrique and Erik I still get a error. See below. apply(veh_drg_animal1[ ,c("readCount","gene_length")] ,1, stats, total=5500) Error in FUN(newX[, i], ...) : element 1 is empty; the part of the args list of '(' being evaluated was: (length_gene) stats<- function(count,length_ge

Re: [R] Passing values to a function when using apply

2010-04-27 Thread Henrique Dallazuanna
Try this: apply( veh_drg_animal1[ , c("readCount","gene_length")] ,1, stats, agr3 = your_constant) On Tue, Apr 27, 2010 at 3:10 PM, 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("readCou

Re: [R] Passing values to a function when using apply

2010-04-27 Thread Erik Iverson
This is not a reproducible example. You might simply want: apply(veh_drg_animal1[, c("readCount", "gene_length")], 1, stats, arg2, arg3) 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 individua

[R] Passing values to a function when using apply

2010-04-27 Thread Abhishek Pratap
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