title: Effective chaining using dplyr in R
body: <p>I have a pretty simple problem which I could hack away at, but I'd rather do things more efficiently in R using things like <code>dplyr.</code> That being said, this question is probably dead simple to someone who is fairly good with that package.</p>
  
  <p>I have a dataframe, 3 columns and 30 rows (for simplicity).  I'd like to calculate the 87th percentile score. After that, I'd like to normalize that score to within a range within 0 and 1. Pretty straightforward: recall normalization is done via</p>
  
  <p><img src="https://i.stack.imgur.com/BSDBb.png" alt="enter image description here"></p>
  
  <p>So the second line below is taking advantage of the power of <code>dplyr</code>. </p>
  
  <pre><code>DF &lt;- data.frame(matrix(runif(90, min=0, max=100), ncol=3,nrow=30))
  DF_87th_percentile &lt;- DF %&gt;% 
      summarise_each(funs(quantile(., c(0.87)))
  </code></pre>
  
  <p>Afterwards, I have the 87th percentile score calculated, but then I stumble and start creating <code>min</code> and <code>max</code> variables, </p>
  
  <pre><code>min &lt;- apply(DF, 2, min)
  max &lt;- apply(DF, 2, max)
  </code></pre>
  
  <p>and then  </p>
  
  <pre><code>normalized_score &lt;- (DF_87th_percentile - min) / (max - min)
  </code></pre>
  
  <p>Is there some way I can rewrite the last parts using <code>dplyr</code>? Like, chain the last parts in perhaps? My efforts have been no good up to now. Thanks for your help in advance.</p>