如何从数据框中选择行

我正在尝试从数据框中提取50行

library(XML)
library(RCurl)

    states = 
    readHTMLTable(getURL("https://simple.wikipedia.org/wiki/List_of_U.S._states_by_area"),stringsAsFactors=FALSE)
    states[3:52]

但是我没有得到我需要的50行,而只是把它放了50次:

 $<NA>
 NULL
inzhatzi 回答:如何从数据框中选择行

您的输出是list,并且不能使用[2:52]来子集元素。您需要在子设置之前将列表转换为data.frame

尝试一下-

library(XML)
library(RCurl)

states = readHTMLTable(getURL("https://simple.wikipedia.org/wiki/List_of_U.S._states_by_area"),stringsAsFactors=FALSE)
as.data.frame(states)[3:52,]
本文链接:https://www.f2er.com/3157350.html

大家都在问