title: Calculating Percentages For "Y" and "N" In Multiple Columns?
body: <p>I want to be able to calculate percentages for "Y" and "N" in my data frame for multiple columns (e.g., Y and Z), so I tried:</p>
  
  <pre><code>Data &lt;- data.frame(
  X = sample(1:10),
  Y = sample(c("Y", "N"), 10, replace = TRUE),
  Z = sample(c("Y", "N"), 10, replace = TRUE), stringsAsFactors=FALSE)
  table(Data$Y)
  prop.table(Data$Y)
  </code></pre>
  
  <p>...but that produces:  Error in sum(x) : invalid 'type' (character) of argument</p>
  
  <p>So, I tried not changing to variable type character and using Factors instead:</p>
  
  <pre><code>Data &lt;- data.frame(
  X = sample(1:10),
  Y = sample(c("Y", "N"), 10, replace = TRUE),
  Z = sample(c("Y", "N"), 10, replace = TRUE))
  table(Data$Y)
  prop.table(Data$Y)
  </code></pre>
  
  <p>...but that produces:  Error in Summary.factor(c(1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), na.rm = FALSE) : ‘sum’ not meaningful for factors</p>
  
  <p>So, I tried transforming it to numeric:</p>
  
  <pre><code>transform(Data, Y = as.numeric(Y))
  </code></pre>
  
  <p>...but that produced the previous factor error.</p>
  
  <p>How do you calculate percentages of "Y" and "N" in multiple columns for use in charts, graphs, etc.?</p>