将 table 导出为 csv 文件,同时保留正确的列号
Exporting table as a csv file while preserving correct column numbers
我将此 table 作为输出,我想将其另存为 csv
文件
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))
以上命令的输出是这样的:
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
为了将上面的 table 导出为 .csv
文件,我使用此代码
write.csv(summary(univariateTable(gender ~ Q(value) + genotype, data=df)),file="file.csv")
问题是四分位数范围的逗号分隔上限值:, 781.0
、, 824.2
和 , 787.5
最终出现在不同的列中,因此第 1 行结束砍掉额外的三列,table 不准确。
有什么办法可以避免吗?
尝试使用 quote=TRUE
选项。 Excel 应该能够区分用于分隔列的 ,
与部分数据。
这是带有一个附加选项的命令。
write.csv(
summary(univariateTable(gender ~ Q(value) + genotype, data=df)),
file="file.csv", quote = TRUE)
我将此 table 作为输出,我想将其另存为 csv
文件
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))
以上命令的输出是这样的:
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
为了将上面的 table 导出为 .csv
文件,我使用此代码
write.csv(summary(univariateTable(gender ~ Q(value) + genotype, data=df)),file="file.csv")
问题是四分位数范围的逗号分隔上限值:, 781.0
、, 824.2
和 , 787.5
最终出现在不同的列中,因此第 1 行结束砍掉额外的三列,table 不准确。
有什么办法可以避免吗?
尝试使用 quote=TRUE
选项。 Excel 应该能够区分用于分隔列的 ,
与部分数据。
这是带有一个附加选项的命令。
write.csv(
summary(univariateTable(gender ~ Q(value) + genotype, data=df)),
file="file.csv", quote = TRUE)