I have this table as an output which I would like to save as a csv
file
value<-cbind(c(rnorm(100,500,90),rnorm(100,800,120)))
genotype<-cbind(c(rep("A",100),rep("B",100)))
gender<-rep(c("M","F","F","F"),50)
df<-cbind(value,genotype,gender)
df<-as.data.frame(df)
colnames(df)<-c("value","genotype","gender")
df$value<-as.numeric(as.character(df$value))
library(Publish)
summary(univariateTable(gender ~ Q(value) + genotype, data=df))
Output of the above command is this:
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
For exporting the above table as a .csv
file, I use this code
write.csv(summary(univariateTable(gender ~ Q(value) + genotype, data=df)),file="file.csv")
The problem is that comma-separated upper values of the interquartile ranges: , 781.0
, , 824.2
, and , 787.5
end up in separate columns, so the row #1 ends up hawing three extra columns and the table is inaccurate.
Is there any way to avoid that?