Skip to content

matrices call a function element-wise

4 messages · zhaoxing731, Jonathan P Daily, Jonathan Christensen +1 more

#
IIRC, R is perfectly able to call matrices as vectors, so you might be 
able to do this:

FT <- function(i) fisher.test(matrix(c(A[i],B[i],C[i],D[i]),2))
E <- sapply(1:1000000, FT)

Though I don't know how much time you will save.
--------------------------------------
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
     - Jubal Early, Firefly

r-help-bounces at r-project.org wrote on 01/03/2011 09:57:14 AM:
http://www.R-project.org/posting-guide.html
#
Hi,

I would recommend reformatting the data as a 2x2x1000 array and using apply.

Jonathan
On Mon, Jan 3, 2011 at 7:57 AM, zhaoxing731 <zhaoxing731 at yahoo.com.cn> wrote: