title: how to calculate mean using apply for this dataframe in r
body: <p>Hi I have df (te_1_melt) like below and i want to calculate the mean of the each tis. How can i do that using apply in r?</p>
  
  <pre><code>                    samples variable       value       tis
  1  GCIMB211_SHADE_INTERNODE      PC1 -0.10329820 INTERNODE
  2       GCIMB211_SHADE_LEAF      PC1  0.25874619      LEAF
  3       GCIMB211_SHADE_ROOT      PC1 -0.28965387      ROOT
  4   GCIMB211_SHADE_SEEDLING      PC1  0.21416352  SEEDLING
  5    GCIMB211_SHADE_SILIQUE      PC1  0.15468874   SILIQUE
  6    GCIMB211_SUN_INTERNODE      PC1 -0.16332945 INTERNODE
  7         GCIMB211_SUN_LEAF      PC1  0.22555539      LEAF
  8         GCIMB211_SUN_ROOT      PC1 -0.24209723      ROOT
  9     GCIMB211_SUN_SEEDLING      PC1  0.25053364  SEEDLING
  10     GCIMB211_SUN_SILIQUE      PC1  0.25269207   SILIQUE
  11   GCR500_SHADE_INTERNODE      PC1 -0.11863509 INTERNODE
  12        GCR500_SHADE_LEAF      PC1  0.28048136      LEAF
  13        GCR500_SHADE_ROOT      PC1 -0.31486321      ROOT
  14    GCR500_SHADE_SEEDLING      PC1  0.04919059  SEEDLING
  15     GCR500_SHADE_SILIQUE      PC1  0.06055899   SILIQUE
  16     GCR500_SUN_INTERNODE      PC1 -0.16754805 INTERNODE
  17          GCR500_SUN_LEAF      PC1  0.29588830      LEAF
  18          GCR500_SUN_ROOT      PC1 -0.30497481      ROOT
  19      GCR500_SUN_SEEDLING      PC1  0.19962128  SEEDLING
  20       GCR500_SUN_SILIQUE      PC1  0.09154038   SILIQUE
  </code></pre>
  
  <p>Since i don't know how this is done using apply, i just did this..</p>
  
  <blockquote>
  <pre><code>INT &lt;- te_1_melt[grep("INTERNODE", te_1_melt$tis),]
  mean(INT[,3])
  
  LEA &lt;- te_1_melt[grep("LEA", te_1_melt$tis),]
  mean(LEA[,3])
  
  ROOT &lt;- te_1_melt[grep("ROOT", te_1_melt$tis),]
  mean(ROOT[,3])
  
  SEED &lt;- te_1_melt[grep("SEEDLING", te_1_melt$tis),]
  mean(SEED[,3])
  
  SIL &lt;- te_1_melt[grep("SILIQUE", te_1_melt$tis),]
  mean(SIL[,3])
  
  comb &lt;- cbind(mean(INT[,3]), mean(LEA[,3]), mean(ROOT[,3]), mean(SEED[,3]), mean(SIL[,3]))
  colnames(comb) &lt;- c("INTERNODE", "LEAF", "ROOT", "SEEDLING", "SILIQUE")
  comb
  comb_mlet &lt;- melt(comb)
  comb_mlet
  </code></pre>
  </blockquote>
  
  <p>Even though i got what i wanted (see below), i know this is not efficient and just wanted to learn how this is done using apply. Anybody help?</p>
  
  <pre><code>&gt; comb_mlet
    Var1      Var2      value
  1    1 INTERNODE -0.1382027
  2    1      LEAF  0.2651678
  3    1      ROOT -0.2878973
  4    1  SEEDLING  0.1783773
  5    1   SILIQUE  0.1398700
  </code></pre>
  
  <p>Thanks
  Upendra</p>