我正在尝试使用 read.table()
函数在 R 中导入我的数据集:
Dataset.df <- read.table("C:\\dataset.txt", header=TRUE)
但我收到了以下错误信息:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
line 1 did not have 145 elements
这是什么意思,我该如何修复?
我正在尝试使用 read.table()
函数在 R 中导入我的数据集:
Dataset.df <- read.table("C:\\dataset.txt", header=TRUE)
但我收到了以下错误信息:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
line 1 did not have 145 elements
这是什么意思,我该如何修复?
在尝试从R文件中读取数据时,我遇到了同样的问题。经过一番摸索,我发现是sep
值导致了这个问题。一旦我使用正确的分隔符尝试,它就像预期的那样工作了。
read.table("file_location/file_name",
sep="." # exact separator as given in file: also "," or "\t" etc.
col_names=c("name_1", "name_2",..))
comment.char = ""
到read.table()
有时会有所帮助。read_delim(file = "filename.tsv", delim = '\t')
以下是该函数的文档:http://rfunction.com/archives/1441