【问题标题】:R how to read a .csv file with different separatorsR如何读取具有不同分隔符的.csv文件
【发布时间】:2014-04-15 14:17:58
【问题描述】:
ItemID,Sentiment,SentimentSource,SentimentText

1,0,Sentiment140,     ok thats it you win.

2,0,Sentiment140,    i think mi bf is cheating on me!!!       T_T

3,0,Sentiment140,"    I'm completely useless rt now. Funny, all I can do is twitter. "

如何将这样的 csv 文件读入 R?

【问题讨论】:

  • 这里到底有什么问题?看起来完全用逗号分隔。
  • read.csv (read.table) 在 R 帮助系统中提供了最容易理解的帮助。阅读各种参数的作用。
  • 很抱歉。我有一个包含 4 个字段和超过 800,000 条推文的大文件。在某一时刻,read.csv 命令无法按我的意愿工作(在 Sentiment 中我找到了文本),我正在寻找发生这种情况的原因。顺便说一句,谢谢大家

标签: r csv separator


【解决方案1】:

使用 read.csv() 读取 csv。您可以将sep="" 指定为您需要的任何内容。但如下所述,, 是分隔符的默认值。

R: Data Input

例如,以逗号作为数据框分隔符的 csv 文件,手动选择文件:

df <- read.csv(file.choose())

【讨论】:

  • header=TRUE, sep = ","read.csv 的默认值,因此无需指定。
猜你喜欢
  • 1970-01-01
  • 2020-03-20
  • 1970-01-01
  • 1970-01-01
  • 2013-09-26
  • 2020-07-18
  • 1970-01-01
  • 2021-01-13
  • 2015-10-15
相关资源
最近更新 更多