I tried to do t-test to all columns (two at a time) of my data frame, and extract only the p-value. Here is what I have come up with:
for (i in c(5:525) ) {
I run this:
tres<-apply(x,1,t.test)
pval<-vapply(tres, "[[", 0, i = "p.value")
It took me a while to divine the "vapply" trick to pull the pvals out of the t.test result object list. (I edited this from 'sapply' because of Henrik's comment below)
If it's a paired t-test, you can just subtract and test for means=0, which gives exactly the same result (that's all a paired t.test is):
tres<-apply(y-x,1,t.test)
pval<-vapply(tres, "[[", 0, i = "p.value")
Again this is a per-row t-test over all columns.