title: extract highest and lowest values for columns in R, as well as row identifiers
body: <p>Say I have some data of the following kind:</p>
  
  <pre><code>df&lt;-as.data.frame(matrix(rnorm(10*10000, 1, .5), ncol=10))
  </code></pre>
  
  <p>I want a new dataframe that keeps the 10 original columns, but for every column retains only the highest 10 and lowest 10 values. Importantly, the rows have names corresponding to id values that need to be kept in the new data frame. </p>
  
  <p>Thus, the end result data.frame is gonna be of dimensions m by 10, where m is very likely to be more than 20. But for every column, I want only 20 valid values. </p>
  
  <p>The only way I can think of doing this is doing it manually per column, using <code>dplyr</code> and arrange, grabbing the top and bottom rows, and then creating a matrix from all the individual vectors. Clearly this is inefficient. Help?</p>