title: Import contingency table (.csv-format) as "table" rather than "data.frame" in R
body: <p>I am working with the (I think) very cool <strong>titanic data</strong> that is publicly available. </p>
  
  <p>There are two principal ways of how to import it to R: </p>
  
  <p>(1) You can either use the <em>built-in dataset</em> <code>Titanic</code> (<code>library(datasets)</code>) or </p>
  
  <p>(2) you can download it as <em>.csv-file</em>, e.g. <a href="http://vincentarelbundock.github.io/Rdatasets/datasets.html" rel="nofollow">here</a>.</p>
  
  <p>Now, the data is aggregated frequency data. I would like to convert the <strong>multi-dimensional contingency table</strong> into an <strong>individual-level data frame</strong>. </p>
  
  <p><strong>PROBLEM:</strong> If I use the built-in dataset, this is no problem; if I use the imported .csv-file, however, it doesn't work. This is the error message I get:</p>
  
  <blockquote>
    <p>Error in rep(1:nrow(tablevars), counts) : invalid 'times' argument In
    addition: Warning message: In expand.table(Titanic.table) : NAs
    introduced by coercion</p>
  </blockquote>
  
  <p><em>Why? And what do I wrong?</em> Many thanks.</p>
  
  <p><strong>R CODE</strong></p>
  
  <pre><code>#required packages
  library(datasets)
  library(epitools)
  
  #(1) Expansion of built-in data set
  data(Titanic)    
  Titanic.raw &lt;- Titanic
  class(Titanic.raw) # data is stored as "table"
  Titanic.expand &lt;- expand.table(Titanic.raw)
  
  #(2) Expansion of imported data set
  Titanic.raw &lt;- read.table("Titanic.csv", header=TRUE, sep=",", row.names=1)
  class(Titanic.raw) #data is stored as "data.frame"
  
  Titanic.table &lt;- as.table(as.matrix(Titanic.raw)) 
  class(Titanic.table) #data is stored as "table"
  
  Titanic.expand &lt;- expand.table(Titanic.table)
  </code></pre>