title: In R, how do I compute factors' percentage given on different variable?
body: <p>I am trying to compute percentage of factors in a variable, and want to make that percentage conditional on other variable.</p>
  
  <p>For example, I have data like this.</p>
  
  <pre><code>State Ideology
  CO    Liberal
  CO    Liberal
  CO    Liberal
  CO    Conservative
  CO    Conservative
  CO    Independent
  DC    Independent
  DC    Conservative
  DC    Liberal
  </code></pre>
  
  <p>I am trying to find the percentage of each Liberal, Conservative, and Independent on each state. </p>
  
  <p>I tried to use ddply like</p>
  
  <pre><code>liberal_per&lt;-ddply(data,.(State), summarize,total=table(Ideology)[1]/sum(Ideology))
  </code></pre>
  
  <p>But it doesn't work. How should I try to find percentage of each factor given on State?</p>
  
  <p>Thank you!</p>