如何在不切断第一行的情况下使用 readHTMLTable [英] How to use readHTMLTable without cutting off first row

查看:23
本文介绍了如何在不切断第一行的情况下使用 readHTMLTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是表格 我想从网上爬到 R

当我运行以下代码时发生的事情是表格的第一行被截断 - 例如,表格以 Justin Tucker 而不是 Steven Gotskowski 开头.

What is happening when I run the following code is the first row of the table is getting cut off- for example, the table starts with Justin Tucker instead of Steven Gotskowski.

library(XML)
kicker_1<- paste("http://www.nfl.com/stats/categorystats?archive=false&conference=null&statisticPositionCategory=FIELD_GOAL_KICKER&season=2013&seasonType=REG&experience=&tabSeq=1&qualified=false&Submit=Go")
kickers_13<- readHTMLTable(kicker_1)

从这里开始,表格的第一行被切断了,我的链接中有什么需要修复的吗?

from this point, the first row of the table is cut off, is there something in my link I need to fix?

推荐答案

您遇到的问题有点奇怪.我通过将 header 参数调整为 FALSE 得到了第一行.不幸的是,您可能需要手动填写列名.

The problem you're having is a bit strange. I got the first line by adjusting the header argument to FALSE. Unfortunately, you'll probably have to manually fill in the column names.

library(XML)
url <- "http://www.nfl.com/stats/categorystats?archive=false&conference=null&statisticPositionCategory=FIELD_GOAL_KICKER&season=2013&seasonType=REG&experience=&tabSeq=1&qualified=false&Submit=Go"
x <- readHTMLTable(url, header = FALSE, which = 1)
head(x)
##   V1                 V2  V3 V4 V5 V6 V7 V8 V9 V10 V11   V12 V13   V14 V15   V16 V17 V18 V19 V20 V21 V22 V23
## 1  1 Stephen Gostkowski  NE  K 38 41 93  0 54 1-1 100   8-8 100 13-13 100 13-11  85 6-5  83  44  44 100   0
## 2  1      Justin Tucker BAL  K 38 41 93  0 61 0-0   0 10-10 100 13-12  92 11-10  91 7-6  86  26  26 100   0
## 3  3     Adam Vinatieri IND  K 35 40 88  1 52 0-0   0   6-6 100 11-10  91 17-15  88 6-4  67  34  34 100   0
## 4  4         Nick Novak  SD  K 34 37 92  2 50 1-1 100   9-9 100 16-13  81   9-9 100 2-2 100  42  42 100   0
## 5  5      Dan Carpenter BUF  K 33 36 92  0 55 0-0   0 13-13 100   6-6 100 11-10  91 6-4  67  32  32 100   0
## 6  5       Mason Crosby  GB  K 33 37 89  0 57 1-1 100 13-13 100   8-8 100   8-6  75 7-5  71  42  42 100   0

这篇关于如何在不切断第一行的情况下使用 readHTMLTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆