title: How to create contigency tables (crosstabs) in R for a subset of columns with categorical data?
body: <p>I have a table whose header looks like this (I've simplified it):</p>
  
  <pre><code>id, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10
  </code></pre>
  
  <p>where each row, except for id, is a categorical variable. Let's name the categories A, B, C, D, E.</p>
  
  <p>I would like to create a contingency table for <em>some</em> of the columns, such as below (for brevity, I have not put sample numbers in the cells). Getting the total column/row would be great, but not mandatory, I can calculate it myself later.</p>
  
  <pre><code>      a1  a2  a3  a4 Total
      ----------------------
      A|
      B|
      C|
      D|
      E|
  Total|
  </code></pre>
  
  <p>Thus, the question is how to create a crosstab based on multiple columns in R? The examples I've seen with table() and xtabs() use a column only. In my case, the columns are adjacent, so one crosstab would summarize columns a1..a4, another a5..a7 and so on. I hope there is an elegant way to do this.</p>
  
  <p>I'm a programmer, but a newbie in R.</p>
  
  <p>Thank you in advance.</p>