title: Create an output matrix or data frame using apply()
body: <p>I've got a frequency cross-tab and would like to use <code>rep()</code> with an <code>apply()</code> function to make a long column of data for each sample (A01, A02 etc) that I can use for mean and stdev stats. The numbers in columns A01, A02 etc are frequency counts of CAG e.g. 6485 counts of 13 CAG.</p>
  
  <p>I've managed to write the function to give the correct results, but the format doesn't appear to be indexable e.g. using <code>sumstats$A01</code> gives <code>NULL</code>. I'd also ideally like the rows and columns inverted in the output table, so columns are mean, sd etc.</p>
  
  <pre><code>data &lt;- data.frame(CAG = c(13, 14, 15), A01 = c(6485,35,132), A02 = c(0,42,56))
  sumstats &lt;- sapply(data[, 2:ncol(data)], function(x) {
  data_e &lt;- rep(data$CAG, x)
  
  list(
    mean = mean(data_e),
    median = median(data_e),
    sd   = sd(data_e)
  )
   })
  
  #Output:
  #sumstats$A01
  #NULL
  </code></pre>