无法载入txt。文件

Can't load in txt. file

我正在尝试读取此数据,但无法成功加载,这是什么问题?

height <- data.table::fread('http://www.stat.nthu.edu.tw/~swcheng/Teaching/stat5410/data/height.txt')
height
Warning message:
In data.table::fread("http://www.stat.nthu.edu.tw/~swcheng/Teaching/stat5410/data/height.txt") :
  Stopped early on line 3. Expected 5 fields but found 3. Consider fill=TRUE and comment.char=. First discarded non-empty line: <<62                65.5           2>>

header有点奇怪,你可以试试(可能会有更好的选择)

x <- read.table(url('http://www.stat.nthu.edu.tw/~swcheng/Teaching/stat5410/data/height.txt'), skip = 2, header= F)

names(x) <- c("Height of Father", "Average Height of Son", "# of Fathers")
x

   Height of Father Average Height of Son # of Fathers
1                62                  65.5            2
2                63                  66.5            6
3                64                  66.8           12
4                65                  66.8           19
5                66                  67.6           27
6                67                  67.8           26
7                68                  68.6           26
8                69                  69.1           26
9                70                  69.5           20
10               71                  70.6           15
11               72                  70.3            8
12               73                  72.0            5