删除R中数据库中的空白



我正试图通过删除所有空值来清理从web上刮来的数据帧。然而;空";值实际上是像这样的空白值"&";。这是我的代码:

url1 <- 'https://www.pro-football-reference.com/draft/2019-combine.htm'
browseURL(url1)
get_pfr_HTML_file1 <- GET(url1)
combine.parsed <- htmlParse(get_pfr_HTML_file1)
page.tables1 <- readHTMLTable(combine.parsed, stringsAsFactors = FALSE)
data2019 <- data.frame(page.tables1[1]) 

请告诉我如何清理2019年的数据。

使用base R,可以在逻辑matrix上使用rowSums来创建逻辑向量,以选择没有空白的行(""(作为行索引

data2019[!rowSums(data2019 == "") > 0,]

data2019 == "" # // returns a logical matrix
rowSums(data2019 == "") # // get the rowwise count of blank elements
rowSums(data2019 == "") > 0 # // convert the count to logical vector
!rowSums(data2019 == "") > 0 # // negate so that it would be 
# // TRUE when all values in a row are non-blank

最新更新