从 R 中的 table 中删除行

Removing rows from a table in R

我使用以下代码将 table 抓取到 R 中。

player.offense.201702050atl = comments.201702050atl[31] %>% html_text() %>% read_html() %>% html_node("#player_offense") %>% html_table()

然后使用以下方法更改了列标签:

colnames(player.offense.201702050atl) = c("Player", "Tm", "Cmp.Passing", "Att.Passing", "Yds.Passing", "TD.Passing", "Int.Passing", "Sk.Passing", "Yds.Sk.Passing", "Lng.Passing", "Rate.Passing", "Att.Rushing", "Yds.Rushing", "TD.Rushing", "Lng.Rushing", "Tgt.Receiving", "Rec.Receiving", "Yds.Receiving", "TD.Receiving", "Lng.Receiving", "Fmb.Fumbles", "FL.Fumbles")

接下来我需要删除第 1、11 和 12 行。

我可以使用:

player.offense.201702050atl.a = player.offense.201702050atl[2:10, ]
player.offense.201702050atl.b = player.offense.201702050atl[13:20, ]
player.offense.201702050atl.c = rbind(player.offense.201702050atl.a, player.offense.201702050atl.b)

但是,我有多个 table 需要类似的操作;而且,我打算消除的行因每一行而异。我希望消除的行的标准是:

第 3 列中的值为 "Cmp" 或 "Passing" 的所有行。

有没有办法 运行 一个函数来解析 table,识别满足上述条件的行,并消除它们?

关于

I desire eliminated is: All rows for which the value in column 3 is either "Cmp" or "Passing".

df <- data.frame(col1 = 1:3, col2 = c('Cmp', 'Passing', 'other'))
df[!df$col2 %in% c('Cmp', 'Passing'), ]
df <- data.frame(x = c('a', 'b', 'c'), y = c('ca', 'cb', 'cc'), z=c('da', 'db', 'dc'))
  x  y  z
 1 a ca da
 2 b cb db
 3 c cc dc
df[-union(which(df$y == 'cc'),which(df$y == 'ca')),]
Result:
  x  y  z
2 b cb db