read.table第15行不包含23个元素-R [英] read.table line 15 does not contain 23 elements - R
本文介绍了read.table第15行不包含23个元素-R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我使用的代码:
d = read.table("Movies.txt",
sep="\t",
col.names=c( "id", "name", "date", "link", "c1", "c2", "c3","c4", "c5", "c6","c7", "c8", "c9","c10", "c11", "c12","c13", "c14", "c15","c16", "c17", "c18", "c19"),
fill=FALSE,
strip.white=TRUE)
这是文本文件:
1 Toy Story (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Toy%20Story%20(1995) 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
2 GoldenEye (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?GoldenEye%20(1995) 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
3 Four Rooms (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Four%20Rooms%20(1995) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
4 Get Shorty (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Get%20Shorty%20(1995) 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0
5 Copycat (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Copycat%20(1995) 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0
6 Shanghai Triad (Yao a yao yao dao waipo qiao) (1995) 01-Jan-95 http://us.imdb.com/Title?Yao+a+yao+yao+dao+waipo+qiao+(1995) 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
7 Twelve Monkeys (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Twelve%20Monkeys%20(1995) 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0
8 Babe (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Babe%20(1995) 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0
9 Dead Man Walking (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Dead%20Man%20Walking%20(1995) 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
10 Richard III (1995) 22-Jan-96 http://us.imdb.com/M/title-exact?Richard%20III%20(1995) 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0
11 Seven (Se7en) (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Se7en%20(1995) 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0
12 "Usual Suspects, The (1995)" 14-Aug-95 "http://us.imdb.com/M/title-exact?Usual%20Suspects,%20The%20(1995)" 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0
13 Mighty Aphrodite (1995) 30-Oct-95 http://us.imdb.com/M/title-exact?Mighty%20Aphrodite%20(1995) 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
14 "Postino, Il (1994)" 01-Jan-94 "http://us.imdb.com/M/title-exact?Postino,%20Il%20(1994)" 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
15 Mr. Holland's Opus (1995) 29-Jan-96 http://us.imdb.com/M/title-exact?Mr.%20Holland's%20Opus%20(1995) 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
16 French Twist (Gazon maudit) (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Gazon%20maudit%20(1995) 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0
17 From Dusk Till Dawn (1996) 05-Feb-96 http://us.imdb.com/M/title-exact?From%20Dusk%20Till%20Dawn%20(1996) 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0
18 "White Balloon, The (1995)" 01-Jan-95 http://us.imdb.com/M/title-exact?Badkonake%20Sefid%20(1995) 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
19 Antonia's Line (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Antonia%20(1995) 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
20 Angels and Insects (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Angels%20and%20Insects%20(1995) 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
很明显,第15行有23个元素.在文本编辑器中应该有选项卡的地方甚至更加清楚.为什么我会收到此错误消息?
It is clear that Line 15 had 23 elements. It is even clearer when in the text editor that there are tabs where they should be. Why would I be getting this error message ?
推荐答案
通过将参数quote = ""
添加到read.table()
来禁用引用.
Disable quoting by adding the parameter quote = ""
to read.table()
.
我认为问题出在整个文件中的各种单引号'
和双引号"
.
I believe the issue is with the various single '
and double-quotes "
throughout the file.
有关更多信息,请参见?read.table
.根据文档,您还可以查看?scan
如何处理嵌入在引号中的引号行为.
Look at ?read.table
for more information. Per the documentation, you can also look at ?scan
for how the behavior of quotes embedded in quotes is handled.
这篇关于read.table第15行不包含23个元素-R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文