title: How to get proportions and counts of a data frame in r
body: <p>I have a data frame like the one below, but with a lot more rows</p>
  
  <pre><code>&gt; df&lt;-data.frame(x1=c(1,1,0,0,1,0),x2=c("a","a","b","a","c","c"))
  &gt; df
    x1 x2
  1  1  a
  2  1  a
  3  0  b
  4  0  a
  5  1  c
  6  0  c
  </code></pre>
  
  <p>From <code>df</code> I want a data frame where the rows are the unique values of <code>df$x2</code> and col1 is the proportion of 1s associated with each letter, and col2 is the count of each letter.  So, my output would be</p>
  
  <pre><code> &gt; getprops(df)
    prop   count
  a  .6666   3
  b  0       1
  c  0.5     2
  </code></pre>
  
  <p>I can think of some elaborate, dirty ways to do this, but I'm looking for something short and efficient.  Thanks</p>