What's the fastest way to apply t.test to each column of a large matrix?

Viewed 6760

Suppose I have a large matrix:

M <- matrix(rnorm(1e7),nrow=20)

Further suppose that each column represents a sample. Say I would like to apply t.test() to each column, is there a way to do this that is much faster than using apply()?

apply(M, 2, t.test)

It took slightly less than 2 minutes to run the analysis on my computer:

> system.time(invisible( apply(M, 2, t.test)))
user  system elapsed 
113.513   0.663 113.519 
2 Answers
Related