【发布时间】:2019-02-05 16:05:00
【问题描述】:
我正在编写几个结果表并以 Excel 格式导出它们。这是我在 R 中的代码的快速示例:
prob = attributes(.Last.value)
clas1=factor(kn1)
#Exporting clas1 into Excel format. The file contains a single column and 430 rows
filename = paste("results", kk, ".csv", sep="")
write.csv(clas1, filename)
#Exporting prob into Excel format. The file also contains a single column and 430 rows
fileprobs = paste("probs", kk, ".csv", sep="")
write.csv (prob$prob, fileprobs)
由于 prob 和 clas1 都已链接,我想将它们导出到一个包含两列和 430 行的表中,而不是将它们拆分为两个不同的文件。
有没有办法做到这一点并将"prob" 作为prob 列的标题和"class" 作为clas1 列的标题?我像这样使用colnames:
write.csv (prob$prob, fileprobs,col.names =c("prob"))
但我收到以下错误消息:
Warning message:
In write.csv(clas1, filename, col.names = c("classes")) :
attempt to set 'col.names' ignored
感谢任何输入。
【问题讨论】:
标签: r export-to-csv