title: crosstable() export to csv
body: <p>Hello so i needed to make a crosstable. I found out there were multiple ways, but there was this function that made the table just like a pivot table from Excel. It works perfectly however i cannot export it to csv, or excel,given the fact that is "Crosstable" class, so it cannot be coerced. </p>
  
  <p>How do i manage to export it to a csv?</p>
  
  <p>See this example</p>
  
  <pre><code>#This way you activate the library
  source("http://pcwww.liv.ac.uk/~william/R/crosstab.r")
  
  # Creating the database
  
  ID &lt;- seq(1:177)
  Age &lt;- sample(c("0-15", "16-29", "30-44", "45-64", "65+"), 177, replace = TRUE)
  Sex &lt;- sample(c("Male", "Female"), 177, replace = TRUE)
  Country &lt;- sample(c("England", "Wales", "Scotland", "N. Ireland"), 177, replace = TRUE)
  Health &lt;- sample(c("Poor", "Average", "Good"), 177, replace = TRUE)
  Survey &lt;- data.frame(Age, Sex, Country, Health)
  
  
  #It resulted in this
  
       Age    Sex    Country  Health
  ## 1 16-29   Male   Scotland    Good
  ## 2   65+ Female      Wales Average
  ## 3  0-15   Male      Wales    Poor
  ## 4 16-29   Male N. Ireland Average
  ## 5 30-44 Female      Wales    Good
  ## 6 30-44 Female      Wales Average
  </code></pre>
  
  <p>but then i wanted the age vs sex cross table</p>
  
  <pre><code># Frequency count
  ct &lt;- crosstab(Survey, row.vars = "Age", col.vars = "Sex", type = "f")
  
  #getting this
  
  ##       Sex Female Male Sum
  ## Age                      
  ## 0-15          19   20  39
  ## 16-29         11   14  25
  ## 30-44         23   17  40
  ## 45-64         15   19  34
  ## 65+           20   19  39
  ## Sum           88   89 177
  </code></pre>
  
  <p>And finally when everyhing was working perfect i get this following message</p>
  
  <pre><code> # Save file as csv
  write.csv(ct,"ct.csv")
  
  Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class ""crosstab"" to a data.frame
  </code></pre>
  
  <p>You can find more information about the function on this website:</p>
  
  <p><a href="http://rstudio-pubs-static.s3.amazonaws.com/6975_c4943349b6174f448104a5513fed59a9.html" rel="nofollow">http://rstudio-pubs-static.s3.amazonaws.com/6975_c4943349b6174f448104a5513fed59a9.html</a></p>