在带有R 1 .csv文件编写不同的数据帧 [英] Write different data frame in one .csv file with R
问题描述
我有3个数据帧,我希望他们写在一个单一的.csv文件,一个是上面的人,而不是在同一个表。因此,在一个CSV文件中3个不同的表。它们都具有相同的尺寸。
I have 3 data frame, and I want them to be written in one single .csv file, one above the others, not in a same table. So, 3 different tables in one csv file. They all have same size.
与 write.csv
问题:它不包含追加的功能
The problem with write.csv
: it does not contain "append" feature
这个问题 write.table
:从 write.table
不被读取pttily $ P $的CSV文件Excel 2010中像那些从 write.csv
The problem with write.table
: csv files from write.table
are not read prettily by Excel 2010 like those from write.csv
帖子我已经阅读并在其中我无法找到解决我的问题:
Post I already read and in which I could not find solution to my problem :
- write.csv() a list of unequally sized data.frames
- Creating a file with more than one data frame
解决方案?
推荐答案
write.csv
只是调用 write.table
引擎盖,用适当的参数下。所以,你可以实现你想要用3调用 write.table
的东西。
write.csv
just calls write.table
under the hood, with appropriate arguments. So you can achieve what you want with 3 calls to write.table
.
write.table(df1, "filename.csv", col.names=TRUE, sep=",")
write.table(df2, "filename.csv", col.names=FALSE, sep=",", append=TRUE)
write.table(df3, "filename.csv", col.names=FALSE, sep=",", append=TRUE)
其实,你可以通过你的数据帧组合成与rbind一个DF,然后调用write.csv一次避免整个问题。
Actually, you could avoid the whole issue by combining your data frames into a single df with rbind, then calling write.csv once.
write.csv(rbind(df1, d32, df3), "filename.csv")
这篇关于在带有R 1 .csv文件编写不同的数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!