text: user4595: I have two normalized gene expression values (log2 of cpm)
  > head(biomarker[,1:5])
                 A2        A3        A4        A6        A7
  A2M    12.4071618 12.631601 12.889748 11.842511 11.574134
  ABCB11  0.5151957  6.176788  5.414905  7.134915  1.247590
  ABCC2   6.7244303  6.487794 10.178615  6.384132  6.089462
  ABCC6   6.3977122  5.823627  7.370761  7.397091  6.071587
  ABCF1   9.1609847  9.893258 10.116638 10.225520 10.838486
  ABCG2   7.6841874  7.738293  6.833152  6.888041  6.030032
  >
  
  And 
  > head(immune[,1:5])
                A2        A3        A4        A6        A7
  A2M    10.904748 11.388404  9.910614 11.513439 12.963609
  ABCB11  5.011380  6.359443  7.145992  8.451947  7.722605
  ABCC2   5.040461  6.477014  3.873996  6.409777  9.133971
  ABCC6   7.798441  7.601848  9.948072 11.628533 12.701460
  ABCF1   8.553597  8.615425 11.145903 10.289098 11.444140
  ABCG2   6.224294  5.629375  8.293416  7.979859  8.603793
  > 
  
  > dim(biomarker)
  [1] 719  56
  > dim(immune)
  [1] 719  56
  > 
  
  I have matched samples in these experiments and same gene too. I could roughly say in both experiments everything has been constant. However, I want to do Student's t-Test to find genes that they had inconsistent gene expression patterns between the two data sets.
  By this function I am getting a list but I don't know how to extract the names of genes with p-value > 0.05 or whatever cut-off
  > f <- function(x,y){
  +     test <- t.test(x,y, paired=TRUE)
  +     out <- data.frame(stat = test$statistic,
  +                       df   = test$parameter,
  +                       pval = test$p.value,
  +                       conl = test$conf.int[1],
  +                       conh = test$conf.int[2]
  +     )
  +     return(out)
  + }
  > t=sapply(seq(ncol(t(biomarker))), function(x) f(t(biomarker)[,x], t(immune)[,x]))
  
  Any help please?
    str(t)
  
      [list output truncated]
       - attr(*, "dim")= int [1:2] 5 719
       - attr(*, "dimnames")=List of 2
        ..$ : chr [1:5] "stat" "df" "pval" "conl" ...
    ..$ : NULL
      >
  
  
  > sapply(t, "[[", "pval")
  Error in FUN(X[[i]], ...) : subscript out of bounds
  >  
  
  
  > pvalueGenes <- sapply(colnames(biomarker),function(i) t.test(biomarker[i, ],immune[i, ], paired = TRUE)$p.value)
  Error in if (stderr < 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") : 
    missing value where TRUE/FALSE needed
  In addition: Warning messages:
  1: In mean.default(x) : argument is not numeric or logical: returning NA
  2: In if (stderr < 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") :
  
   Show Traceback
  
   Rerun with Debug
   Error in if (stderr < 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") : 
    missing value where TRUE/FALSE needed
  
  
  user131: From your example we are comparing samples not genes, I think we need to run the test row wise, something like this:
  pvalueGenes <- sapply(colnames(biomarker),
                        function(i) t.test(biomarker[i, ],
                                           immune[i, ], paired = TRUE)$p.value)
  
  names(pvalueGenes)[ pvalueGenes < 0.05 ]
  
  
  user776: Starting from the definition of t:
  ...
  > t <- sapply(seq(ncol(t(biomarker))), function(x) f(t(biomarker)[,x], t(immune)[,x]))
  
  Set the column names to the gene names from one or the other of your conditions:
  > colnames(t) <- rownames(immune)
  
  Set the cutoff:
  > cutoff <- 0.05
  
  Filter for rows which meet the p-value cutoff criterium, and get their column names (gene names):
  > colnames(t)[which(unlist(lapply(t["pval",], function(x) x < cutoff)))]
  [1] "ABCC6" 
  ...
  
  Only one gene name is reported here, using your demo datasets. Adjust your cutoff and criterium logic, as needed. For example, I filter here for gene names where the p-value is less than the cutoff; however, from your question, you may be asking for the inverse, for whatever reason, so you could change < to >=.
  
original_text: 4595: <p>I have two normalized gene expression values (log2 of cpm)</p>
  
  <pre><code>&gt; head(biomarker[,1:5])
                 A2        A3        A4        A6        A7
  A2M    12.4071618 12.631601 12.889748 11.842511 11.574134
  ABCB11  0.5151957  6.176788  5.414905  7.134915  1.247590
  ABCC2   6.7244303  6.487794 10.178615  6.384132  6.089462
  ABCC6   6.3977122  5.823627  7.370761  7.397091  6.071587
  ABCF1   9.1609847  9.893258 10.116638 10.225520 10.838486
  ABCG2   7.6841874  7.738293  6.833152  6.888041  6.030032
  &gt;
  </code></pre>
  
  <p>And </p>
  
  <pre><code>&gt; head(immune[,1:5])
                A2        A3        A4        A6        A7
  A2M    10.904748 11.388404  9.910614 11.513439 12.963609
  ABCB11  5.011380  6.359443  7.145992  8.451947  7.722605
  ABCC2   5.040461  6.477014  3.873996  6.409777  9.133971
  ABCC6   7.798441  7.601848  9.948072 11.628533 12.701460
  ABCF1   8.553597  8.615425 11.145903 10.289098 11.444140
  ABCG2   6.224294  5.629375  8.293416  7.979859  8.603793
  &gt; 
  
  &gt; dim(biomarker)
  [1] 719  56
  &gt; dim(immune)
  [1] 719  56
  &gt; 
  </code></pre>
  
  <p>I have matched samples in these experiments and same gene too. I could roughly say in both experiments everything has been constant. However, I want to do Student's t-Test to find genes that they had inconsistent gene expression patterns between the two data sets.</p>
  
  <p>By this function I am getting a list but I don't know how to extract the names of genes with p-value > 0.05 or whatever cut-off</p>
  
  <pre><code>&gt; f &lt;- function(x,y){
  +     test &lt;- t.test(x,y, paired=TRUE)
  +     out &lt;- data.frame(stat = test<span class="math-container">$statistic,
  +                       df   = test$</span>parameter,
  +                       pval = test<span class="math-container">$p.value,
  +                       conl = test$</span>conf.int[1],
  +                       conh = test$conf.int[2]
  +     )
  +     return(out)
  + }
  &gt; t=sapply(seq(ncol(t(biomarker))), function(x) f(t(biomarker)[,x], t(immune)[,x]))
  </code></pre>
  
  <p>Any help please?</p>
  
  <pre><code>  str(t)
  
      [list output truncated]
       - attr(*, "dim")= int [1:2] 5 719
       - attr(*, "dimnames")=List of 2
        ..<span class="math-container">$ : chr [1:5] "stat" "df" "pval" "conl" ...
    ..$</span> : NULL
      &gt;
  
  
  &gt; sapply(t, "[[", "pval")
  Error in FUN(X[[i]], ...) : subscript out of bounds
  &gt;  
  
  
  &gt; pvalueGenes &lt;- sapply(colnames(biomarker),function(i) t.test(biomarker[i, ],immune[i, ], paired = TRUE)<span class="math-container">$p.value)
  Error in if (stderr &lt; 10 * .Machine$</span>double.eps * abs(mx)) stop("data are essentially constant") : 
    missing value where TRUE/FALSE needed
  In addition: Warning messages:
  1: In mean.default(x) : argument is not numeric or logical: returning NA
  2: In if (stderr &lt; 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") :
  
   Show Traceback
  
   Rerun with Debug
   Error in if (stderr &lt; 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") : 
    missing value where TRUE/FALSE needed
  </code></pre>
   131: <p>From your example we are comparing samples not genes, I think we need to run the test row wise, something like this:</p>
  
  <pre><code>pvalueGenes &lt;- sapply(colnames(biomarker),
                        function(i) t.test(biomarker[i, ],
                                           immune[i, ], paired = TRUE)$p.value)
  
  names(pvalueGenes)[ pvalueGenes &lt; 0.05 ]
  </code></pre>
   776: <p>Starting from the definition of <code>t</code>:</p>
  
  <pre><code>...
  &gt; t &lt;- sapply(seq(ncol(t(biomarker))), function(x) f(t(biomarker)[,x], t(immune)[,x]))
  </code></pre>
  
  <p>Set the column names to the gene names from one or the other of your conditions:</p>
  
  <pre><code>&gt; colnames(t) &lt;- rownames(immune)
  </code></pre>
  
  <p>Set the cutoff:</p>
  
  <pre><code>&gt; cutoff &lt;- 0.05
  </code></pre>
  
  <p>Filter for rows which meet the p-value cutoff criterium, and get their column names (gene names):</p>
  
  <pre><code>&gt; colnames(t)[which(unlist(lapply(t["pval",], function(x) x &lt; cutoff)))]
  [1] "ABCC6" 
  ...
  </code></pre>
  
  <p>Only one gene name is reported here, using your demo datasets. Adjust your cutoff and criterium logic, as needed. For example, I filter here for gene names where the p-value is <em>less</em> than the cutoff; however, from your question, you may be asking for the inverse, for whatever reason, so you could change <code>&lt;</code> to <code>&gt;=</code>.</p>
  