The t.test is used to compare two data sets. Collecting two data sets each from three different columns of a matrix can be done like this:
data_a = c(x[,2:4])
data_b = c(x[,4:8])
These two data sets can be evaluated using t.test at this point:
t.test(data_a, data_b)
Collecting the data from three columns each for two different compounds for a given row (amino acid) we modify and add a loop:
x <- matrix(rnorm(24, mean=0, sd=1), 4, ncol=6)
x
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.4810307 0.3996071 0.90663635 0.7487048 0.5787846 2.0231681
[2,] -2.0454921 -0.1225105 -1.04447522 0.9325333 -1.7782776 0.6856150
[3,] -0.3099937 1.2079548 -0.03835271 0.2751349 1.0111554 -0.4862846
[4,] -0.2834953 0.1930481 -0.57968344 0.1204925 -0.5015843 0.3690397
for(i in 1:nrow(x)){
data_a = c(x[i, 1:3])
data_b = c(x[i, 4:6])
print(t.test(data_a, data_b))
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…