title: Using table() to create 3 variable frequency table in R
body: <p>I'm new to R and seeking some help.  I understand the following problem is fairly simple and have looked for similar questions. None give quite the answer I'm looking for - any help would be appreciated.</p>
  
  <p><strong>The problem:</strong></p>
  
  <p>Producing a frequency table using the <code>table()</code> function for three variables with data in the format:</p>
  
  <pre><code>    Var1    Var2   Var3
  1   0        1        0
  2   0        1        0
  3   1        1        1
  4   0        0        1
  </code></pre>
  
  <p>Where, 0 = "No" and 1 = "Yes"</p>
  
  <p>And the final table is in the following format with variables and values labelled:</p>
  
  <pre><code>           Var3
             Yes   No
  Var1  Yes   1     0
        No    1     2
  Var2  Yes   1     2
        No    1     0
  </code></pre>
  
  <p><strong>What I have tried so far:</strong></p>
  
  <p>Using the following code I'm able to produce a 2 variable table, with labels for the variables but not for the values (ie. No and Yes).  </p>
  
  <pre><code>table(data$Var1, data$Var3, dnn = c("Var1", "Var3"))
  </code></pre>
  
  <p>It looks like this:</p>
  
  <pre><code>      Var3
  Var1  0  1
     0  2  1
     1  0  1
  </code></pre>
  
  <p>In trying to label the row and column values (0 = No and 1= Yes) I understand <code>row.names</code> and <code>responseName</code> can be used, however the following attempt to label row names gives an <code>all arguments must have the same length</code> error.</p>
  
  <pre><code>&gt; table(data$Var1, data$Var2, dnn = c("Var1", "Var2"), row.names = c("No", "Yes"))
  </code></pre>
  
  <p>I have also tried using <code>ftable()</code> however the shape of the table produced using code below is not correct resulting in incorrect frequencies for the problem.  The issue with labeling row &amp; col values persists.</p>
  
  <pre><code>&gt; ftable(data$Var1, data$Var2, data$Var3, dnn = c("Var1", "Var2", "Var3"))
        Var3  0  1
  Var1 Var2             
  0     0     0  1
        1     2  0
  1     0     0  0
        1     0  1
  </code></pre>
  
  <p>Any help in using <code>table()</code> to produce a table of the shape desired would be greatly appreciated.</p>