title: Use variable number of columns/loop inside dplyr::summarize
body: <p>Currently I have the following in R.
  Its simply giving me total number of males and females city-wise. </p>
  
  <pre><code>df %&gt;%
      group_by(city) %&gt;%
        dplyr::summarize(pct.female = sum(sbq04 == "female"), pct.male = sum(sbq04 == "male"))
  </code></pre>
  
  <p>Say I want to do the same summarization on a column <code>sbq05</code>
  The said column contains around 18 distinct values <code>("first value", "second value", ....)</code>.
  I can do something similar to what I did above like this:</p>
  
  <pre><code>df %&gt;%
      group_by(city) %&gt;%
        dplyr::summarize(pct.firstvalue = sum(sbq05 == "first value"), pct.secondvalue = sum(sbq05 == "second value"), ....)
  </code></pre>
  
  <p>However I would have to explicitly type out all the 18 values. Is there any shorter way.</p>
  
  <p>I was thinking of getting all the distinct values of my column in a vector. And then loop inside summarize applying sum on each distinct value.
  I am very new to R so i dont know if that is technically possible, or if there is any better way. </p>
  
  <p>Any help would be appreciated.</p>