title: rbind formatting issues when exporting to csv
body: <p>What I am doing is crosstabulating a range of variables in a dataset (kol) with one crossing variable (cross) and then exporting the result into a csv.</p>
  
  <pre><code>library(dplyr)
  
  cross &lt;- dataset$crossingvariable
  kol &lt;- select(dataset,var.first:var.last)
  
  myfunction &lt;- function(x) {
    table1 &lt;- table(cross, x)
    table2 &lt;- prop.table(table1, 1)
    table3 &lt;- data.frame(table2)
  }
  
  dtfr &lt;- lapply(kol,FUN=myfunction)
  dtfr2 &lt;- do.call("rbind", dtfr)
  
  write.csv(dtfr2, file="C:/Users/Gebruiker/Documents/statistics/test.csv")
  </code></pre>
  
  <p>The problem is that the two dtfr (dtfr and dtfr2) steps mess up the formatting. What it needs to do is that every element in dtfr is arranged vertically under one another when exporting to csv. dtfr2 does this, but in the process it also rearranges the tables. So in step dtfr the formatting is still correct if I include as.data.frame.matrix with table3 (shown below) (<a href="http://i.stack.imgur.com/PTZEq.jpg" rel="nofollow">how the formatting should be, shown in r console and with as.data.frame.matrix in table3</a>), in step dtfr2 it has moved (<a href="http://i.stack.imgur.com/9gZfE.png" rel="nofollow">Incorrect formatting in csv</a>). Step dtfr2 however is needed to get it vertically under one another in the csv file.</p>
  
  <p>When I change table3 to:</p>
  
  <pre><code>library(dplyr)
  
  cross &lt;- dataset$crossingvariable
  kol &lt;- select(dataset,var.first:var.last)
  
  myfunction &lt;- function(x) {
    table1 &lt;- table(cross, x)
    table2 &lt;- prop.table(table1, 1)
    table3 &lt;- as.data.frame.matrix(table2)
  }
  
  dtfr &lt;- lapply(kol,FUN=myfunction)
  dtfr2 &lt;- do.call("rbind", dtfr)
  
  write.csv(dtfr2, file="C:/Users/Gebruiker/Documents/statistics/test.csv")
  </code></pre>
  
  <p>dtfr gets a correct output (shown above). But at this point dtfr2 shows the following error message when I run the script: </p>
  
  <pre><code>Error in rbind(deparse.level, ...) : 
   numbers of columns of arguments do not match
  </code></pre>
  
  <p>I assume it has something to do with unequal amounts of columns in the different variables I am crosstabulating. Most of them are nominal or ordinal variables, so some of them have three categories and some of them have five.</p>
  
  <p>I can't manage to find how to fix this, mostly having to do with my limited r knowledge. I googled the problem and looked on stack overflow which yielded some similar problems but all the offered solutions didn't work in my case. Again this has alot to do with me not really knowing enough about r yet, but some help pointing me in the right direction would be very much appreciated.</p>