title: How to create a table of proportion in R
body: <p>How can I create a table of proportions and include the variable names in the first column of the table?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>time      &lt;- c("Morning", "Evening" ,"Morning", "Morning", "Afternoon", "Evening", "Afternoon")
  dollar    &lt;- c("1-5", "6-10", "11-15", "1-5", "1-5", "6-10", "6-10")
  with_kids &lt;- c("no", "yes", "yes", "no", "no", "yes", "yes")
  cluster   &lt;- c(1,1,2,3,2,2,3)    
  dat       &lt;- data.frame(time, dollar, with_kids, cluster)
  
  myList      &lt;- lapply(dat[head(names(dat), -1)], table, dat$cluster)    
  myList_Prop &lt;- lapply(myList, prop.table, margin=2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/9XbRw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9XbRw.jpg" alt="enter image description here"></a></p>
  
  <p>Original question: <a href="https://stackoverflow.com/questions/45354436/table-of-categorical-variables-by-a-grouping-variable-in-r/45355374#45355374">Table of categorical variables by a grouping variable in R</a></p>