read.table line 15 does not contain 23 elements - R

限于喜欢 提交于 2019-12-13 00:32:03

问题


here is the code I used:

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)

and here is the text file:

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

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 ?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/27321849/read-table-line-15-does-not-contain-23-elements-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!