-3

我想知道我们是否可以使用带有发布 html 表的页面的 url 的 readr 包访问 html 表。例如,我想在 要加载到 R的页面上导入表格。

4

1 回答 1

5

I'm not sure what a 'chizamp' might be, but Scriven is correct, albeit with a bit of extra noodling needed to figure out which of the multiple tables returned by XML::readHTMLTables might be the one you wanted:

> library(XML)
> help(pack=XML)
> sports <- readHTMLTable("http://sports.yahoo.com/nfl/stats/byteam?group=Offense&cat=Total&conference=NFL&year=season_2010&sort=530&old_category=Total&old_group=Offense")
> str(sports[[1]])
'data.frame':   1 obs. of  2 variables:
 $ V1: Factor w/ 1 level "": 1
 $ V2: Factor w/ 1 level "Search SportsSearch Web": 1
> str(sports[[2]])
'data.frame':   2 obs. of  1 variable:
 $ : Factor w/ 2 levels "","Sortable Stats": 2 1
> length(sports)
[1] 8
> str(sports[[8]])
 NULL
# top of str() on the seventh item in that list
str(sports[[7]])
'data.frame':   32 obs. of  28 variables:
 $ Team     : Factor w/ 32 levels "Arizona Cardinals",..: 19 26 24 14 2 23 21 9 13 12 ...
 $          : Factor w/ 1 level "": 1 1 1 1 1 1 1 1 1 1 ...
 $ G        : Factor w/ 1 level "16": 1 1 1 1 1 1 1 1 1 1 ...
 $          : Factor w/ 1 level "": 1 1 1 1 1 1 1 1 1 1 ...
 $ Pts/G    : Factor w/ 28 levels "12.3","16.9",..: 28 27 26 25 24 23 22 22 21 20 ...
于 2016-05-24T20:52:37.013 回答