How to read a .csv file containing apostrophes into R?

前端 未结 3 740
故里飘歌
故里飘歌 2021-02-06 22:51

I am having difficulty getting R to read a .txt or .csv file that contains apostrophes.

Some of my columns contain descriptive text, such as \"Attends to customers\' n

相关标签:
3条回答
  • 2021-02-06 22:59

    Thoroughly studying the options in ?read.table will pay off in the long run. The default values for quoting characters is quote = "\"'", which is really only two characters after R parses that expression, single-quote and double-quote. You can remove them both from consideration using quotes=NA. It's sometimes necessary to also remove the 'comment.char' defaulting to "#", and it may be helpful to change 'as.is' to TRUE to prevent strings from getting converted to factors.

    0 讨论(0)
  • 2021-02-06 23:09

    By default, read.table sees single and double quotes as quoting characters. You need to add quote="\"" to your read.table call. Or, you could just use read.csv, which only sees double quotes as quoting characters by default.

    0 讨论(0)
  • 2021-02-06 23:22

    Setting the parameter quote="\\" in read.table should do the trick.

    0 讨论(0)
提交回复
热议问题