使用 R 将行追加到 .csv 文件

Posted

技术标签:

【中文标题】使用 R 将行追加到 .csv 文件【英文标题】:Using R to append a row to a .csv file 【发布时间】:2017-10-03 00:28:46 【问题描述】:

我有一个包含 175 行和 6 列的 .csv 文件。我想追加第 176 行。我的代码如下:

x <- data.frame('1', 'ab', 'username', '<some.sentence>', '2017-05-04T00:51:35Z', '24')

write.table(x, file = "Tweets.csv", append = T)

我希望看到的是: enter image description here

相反,我的结果是: enter image description here

我应该如何更改我的代码?

【问题讨论】:

在你的write.table(..)中添加quote=F 还添加 sep = "," 【参考方案1】:
write.table(x, file = "Tweets.csv", sep = ",", append = TRUE, quote = FALSE,
  col.names = FALSE, row.names = FALSE)

【讨论】:

如何将行附加到 csv 文件的头部而不是附加到底部?

以上是关于使用 R 将行追加到 .csv 文件的主要内容,如果未能解决你的问题,请参考以下文章