doing t.test for columns for each row in data set

后端 未结 4 1763
悲&欢浪女
悲&欢浪女 2020-12-10 23:11

I have a set of data x which consists of 12 columns and 167 rows. The first column is compound Id for each row. I want to run a t.test for 3 column

4条回答
  •  粉色の甜心
    2020-12-10 23:42

    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))
    }
    

提交回复
热议问题