title: In R, how can I elegantly compute the medians for multiple columns, and then count the number of cells in each row that exceed the median?
body: <p>Suppose I have the following data frame:</p>
  
  <pre><code>Base Coupled Derived Decl
     1       0       0    1
     1       7       0    1
     1       1       0    1
     2       3      12    1
     1       0       4    1
  </code></pre>
  
  <p>Here is the <code>dput</code> output:</p>
  
  <pre><code>temp &lt;- structure(list(Base = c(1L, 1L, 1L, 2L, 1L), Coupled = c(0L,7L, 1L, 3L, 0L), Derived = c(0L, 0L, 0L, 12L, 4L), Decl = c(1L, 1L, 1L, 1L, 1L)), .Names = c("Base", "Coupled", "Derived", "Decl"), row.names = c(NA, 5L), class = "data.frame")
  </code></pre>
  
  <p>I want to compute the median for each column. Then, for each row, I want to count the number of cell values greater than the median for their respective columns and append this as a column called AboveMedians.</p>
  
  <p>In the example, the medians would be <code>c(1,1,0,1)</code>. The resulting table I want would be</p>
  
  <pre><code>Base Coupled Derived Decl AboveMedians
     1       0       0    1            0
     1       7       0    1            1
     1       1       0    1            0
     2       3      12    1            3
     1       0       4    1            1
  </code></pre>
  
  <p>What is the elegant R way to do this? I have something involving a for-loop and sapply, but this doesn't seem optimal.</p>
  
  <p>Thanks. </p>