This should work. First create some reproducible data:
> set.seed(42)
> temp.matrix <- matrix(rnorm(255*13), 255, 13)
Then you need to send each row to t.test() using apply() extracting the
statistic with [[1]]:
> result <- apply(temp.matrix, 1, function(x) (t.test(x[3:7], x[8:12],
paired=TRUE)[[1]]))
> str(result)
num [1:255] -0.195 0.307 1.214 2.221 0.633 ...> quantile(result)
0% 25% 50% 75% 100%
-3.39194814 -0.80146023 0.02383907 0.71836716 5.88806695
-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Vincenzo
Prestigiacomo
Sent: Wednesday, November 16, 2016 2:07 PM
To: r-help at r-project.org
Subject: [R] R help
Hello everybody,
I am a student at Unibas and I am trying to run a two sample t-test on a matrix
which is a
255*13 matrix (see attachment). I want to run the t-test, row-wise, with the
columns 3:7 being a part of the first group and columns
8-12 being a part of the second group.
I tried running something like (temp.matrix being my 255*13
matrix)
t.test(temp.matrix[,3:7],temp.matrix[,8:12],paired=TRUE)
or somthing like
as.numeric(t.test(temp.matrix[,3:7],temp.matrix[,8:12],paired=TRUE)[[1]])
so as to only capture the t-value alone and
and I get a result for the whole matrix instead of a row-wise
result.
I really hope you can help me
Thanks
Vincenzo