如何将此文本文件转换为R data.frame

时间:2018-01-14 13:37:28

标签: r csv fixed-width

This is the text file

y <- read.table("https://afltables.com/afl/stats/biglists/bg2.txt", skip = 1, header = T, sep = ' ')
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 3 did not have 30 elements

1 个答案:

答案 0 :(得分:2)

你可以试试这个。

y <- read.fwf("https://afltables.com/afl/stats/biglists/bg2.txt", skip = 3, widths=c(6, 9, 30, 2), col.names = c("Rank","Games","Player","Teams" ))