我尝试在R中读取tsv文件,但会引发有关元素不匹配的错误

问题描述 投票:0回答:1

这是我的代码:

imdb <- read.table(file = "/data.tsv", sep = "\t", header = TRUE, na.strings = "")

错误:

Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 11 did not have 9 elements

文件,您可以在其中查看列的分隔方式,等等。

screenshot of tsv

实际上,第11行有9个元素,那么可能是什么问题?

tt0000010   short   Exiting the Factory La sortie de l'usine Lumière à Lyon 0   1895    \N  1   Documentary,Short
tt0000011   short   Akrobatisches Potpourri Akrobatisches Potpourri 0   1895    \N  1   Documentary,Short
tt0000012   short   The Arrival of a Train  L'arrivée d'un train à La Ciotat    0   1896    \N  1   Action,Documentary,Short
r
1个回答
0
投票

当行中有更多元素时,将是一个问题。我们可以使用fill = TRUE

imdb <- read.table(file = "/data.tsv", sep = "\t",
        header = TRUE, na.strings = "", fill = TRUE)
© www.soinside.com 2019 - 2024. All rights reserved.