[R] How to extract x rows to get x pvalues using t.test

Liaw, Andy andy_liaw at merck.com
Wed Mar 16 01:43:26 CET 2005


> From: Adaikalavan Ramasamy
> 
> You will need to _apply_ the t-test row by row. 
> 
>    apply( genes, 1, function(x) t.test( x[1:2], x[3:4] )$p.value )
> 
> apply() is a C optimised version of for. Running the above code on a
> dataset with 56000 rows and 4 columns took about 63 seconds on my 1.6
> GHz Pentium machine with 512 Mb RAM. See help("apply") for 
> more details.

That's not true.  In R, there's a for loop hidden inside apply() (just look
at the source).  In S-PLUS, C level looping is done in some situations, and
for others lapply() is used.

Andy

 
> Regards, Adai
> 
> 
> 
> On Tue, 2005-03-15 at 11:59 -0600, Jagarlamudi, Choudary wrote:
> > Hi all,
> >  
> >   My data
> > genes
> >      [,1] [,2] [,3] [,4]
> > [1,]   25   72   23   55
> > [2,]   34   53   41   33
> > [3,]   26   43   26   44
> > [4,]   36   64   64   22
> > [5,]   47   72   67   34
> > 
> >  stu<-t.test(genes[,1:2],genes[,3:4])
> > > stu$p.value
> > [1] 0.4198002
> > 
> > i get 1 pvalue for the entire col1:col2  Vs col3:col4. I am 
> trying to get 5 p values for the 5 rows i have.
> > I am trying to avoid a for loop coz my actual data has 
> 56000 rows and its taking more than 4 minutes to
> > compute.
> >  
> > Thanks in advance.
> >  
> > Choudary Jagarlamudi
> > Instructor
> > Southwestern Oklahoma State University
> > STF 254
> > 100 campus Drive
> > Weatherford OK 73096
> > Tel 580-774-7136
> > 
> > 	[[alternative HTML version deleted]]
> > 
> > ______________________________________________
> > R-help at 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
> >
> 
> 
> ______________________________________________
> R-help at 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
> 
> 
>




More information about the R-help mailing list