0

I have two groups: high and low for weight. In addition I have gene expression values for all genes within each group with three varieties:

  gene  Variety_1   Variety_2   Variety_3   Variety_4   Variety_5   Variety_6
Weight  75.01776435 61.33770069 58.94255236 1.378325093 1.257405065 1.238147023
    A1  0.677707    0.546048    1.734473    0.375743    0.337179    0.777027
    A2  7.981616    3.183075    14.36619    6.108213    8.375638    21.607289
    A3  0.867021    2.018648    2.476652    1.634256    1.853648    3.682622
    A4  0           0           0           1.111973    1.970236    5.323712
    A5  1.508041    12.609049   8.554698    2.525282    3.461804    12.971696
    A6  0.371842    1.089097    1.484137    0.94704     0.07742     1.075424
    A7  0           0           8.090433    0           0           0
    A8  0           0           0           0           0           0

I want to perform a t-test for each gene (row) between high (variety 1,2,3) and low (variety 4,5,6) weight varieties.

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
Jessica
  • 391
  • 1
  • 3
  • 16
  • Yes, I have a list of genes. I have a csv file. I am not sure if that's what you're asking. – Jessica May 13 '20 at 19:27
  • I see. Actually, I have a csv file for all genes and varieties without any groups. I made groups based on weight data and chose three varieties each for high and low weight. – Jessica May 13 '20 at 19:29
  • I added weight which I used as a row to get gene expression values. – Jessica May 13 '20 at 19:33
  • 1
    I have updated the question as the data without making any groups. – Jessica May 13 '20 at 19:37
  • 1
    Does this answer your question? [doing t.test for columns for each row in data set](https://stackoverflow.com/questions/28119894/doing-t-test-for-columns-for-each-row-in-data-set) – Karolis Koncevičius May 13 '20 at 21:27

2 Answers2

0

We can use apply with MARGIN =1

df1$pval <- c(NA, apply(df1[-1,-1], 1, function(x) t.test(x[1:3], x[4:6])$p.value))
akrun
  • 874,273
  • 37
  • 540
  • 662
0

Here is one approach with external library:

library(matrixTests)
row_t_welch(x[,1:3], x[,4:6])
Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89