在文本文件中读取的问题

use*_*211 1 csv file-io text-processing r

我正在尝试使用以下代码将文本文件读入R:

d = read.table("test_data.txt")
Run Code Online (Sandbox Code Playgroud)

它返回以下错误消息:

"Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 2 did not have 119 elements"
Run Code Online (Sandbox Code Playgroud)

我试过这个:

read.table("man_cohort9_check.txt", header=T, sep="\t")
Run Code Online (Sandbox Code Playgroud)

但它给出了这个错误:

"Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 43 did not have 116 elements"
Run Code Online (Sandbox Code Playgroud)

我不明白出了什么问题?

Mic*_*ele 5

这是因为您的文件包含不同列数的行.要开始调查,您可以运行:

d = read.table("test_data.txt", fill=TRUE, header=TRUE, sep="\t")
Run Code Online (Sandbox Code Playgroud)