Exporting table as a csv file while preserving correct column numbers
<p>I have this table as an output which I would like to save as a <code>csv</code> file</p>

<pre><code>value&lt;-cbind(c(rnorm(100,500,90),rnorm(100,800,120)))
genotype&lt;-cbind(c(rep("A",100),rep("B",100)))
gender&lt;-rep(c("M","F","F","F"),50)
df&lt;-cbind(value,genotype,gender)
df&lt;-as.data.frame(df)
colnames(df)&lt;-c("value","genotype","gender")
df$value&lt;-as.numeric(as.character(df$value))
library(Publish)
summary(univariateTable(gender ~ Q(value) + genotype, data=df))
</code></pre>

<p>Output of the above command is this:</p>

<pre><code>  Variable        Level   gender = F (n=150)    gender = M (n=50)
1    value median [iqr] 651.4 [499.2, 781.0] 636.8 [539.8, 824.2]
2 genotype            A            75 (50.0)            25 (50.0)
3                     B            75 (50.0)            25 (50.0)
         Total (n=200) p-value
1 644.6 [509.8, 787.5]  0.4859
2           100 (50.0)        
3           100 (50.0)  1.0000
</code></pre>

<p>For exporting the above table as a <code>.csv</code> file, I use this code</p>

<pre><code>write.csv(summary(univariateTable(gender ~ Q(value) + genotype, data=df)),file="file.csv")
</code></pre>

<p>The problem is that comma-separated upper values of the interquartile ranges: <code>, 781.0</code>, <code>, 824.2</code>, and <code>, 787.5</code> end up in separate columns, so the row #1 ends up hawing three extra columns and the table is inaccurate.</p>

<p>Is there any way to avoid that?</p>