当前位置: 动力学知识库 > 问答 > 编程问答 >

r - How to write multiple xtabs in a CSV file?

问题描述:

For writing a single xtab, I have used:

write.csv(xtabData1, "analysis.csv")

For appending one more xtab to the same csv file, I tried:

write.csv(xtabData2, "analysis.csv", append=T)

But this throws a warning "attempt to set 'append' ignored" and overwrites the csv file.

网友答案:

One solution would be to join the tab data first using rbind, e.g.

write.csv(rbind(xtabData1, xtabData2), file="analysis.csv")
网友答案:

The append option is disabled in write.csv(). write.csv() is just a wrapper function for write.table(). Here;s more from the help file.

write.csv and write.csv2 provide convenience wrappers for writing CSV files. They set sep and dec (see below), qmethod = "double", and col.names to NA if row.names = TRUE (the default) and to TRUE otherwise. write.csv uses "." for the decimal point and a comma for the separator. write.csv2 uses a comma for the decimal point and a semicolon for the separator, the Excel convention for CSV files in some Western European locales. These wrappers are deliberately inflexible: they are designed to ensure that the correct conventions are used to write a valid file. Attempts to change append, col.names, sep, dec or qmethod are ignored, with a warning.

Use write.table() instead (with sep="," and whatever other settings you'd like).

分享给朋友:
您可能感兴趣的文章:
随机阅读: