• R语言
  • read.table读取文件中含有'单引号的文件出错

比如下面这段字符:

abc c

a b

abc 5'a

a b

保存成文本文件为test.txt

<br />
> read.table("test.txt",sep="\t")<br />
  V1 V2<br />
1  a  b<br />
Warning message:<br />
In read.table("test.txt", sep = "\t") :<br />
  incomplete final line found by readTableHeader on 'test.txt'<br />
</p>

分析一下原因,把文件中的单引号去掉,结果就没问题了。如下

<br />
> read.table("test.txt",sep="\t")<br />
   V1 V2<br />
1 abc  c<br />
2   a  b<br />
3 abc 5a<br />
4   a  b<br />
</p>

那么,该怎么读取含有单引号的文本文件呢?

> read.table("clipboard",sep="\t",head=T,quot="")

abc c

1 a b

2 abc 5'a

3 a b

回复 第2楼 的 sociology:多谢!