显示以两列的值为条件的行-R

  • 本文关键字:条件 两列 显示 r
  • 更新时间 :
  • 英文 :

黑人>>已婚<1th>节点<2th>re74<5th>re750<1>0<1>0
治疗 年龄 教育hispanic
1: 0 23 10 1010
2: 0 26 12 0
3: 0 22 9
4: 0 18 9
(¬_¬)df <- data.frame(
...   stringsAsFactors = FALSE,
...              treat = c("1:", "2:", "3:", "4:"),
...                age = c(0L, 0L, 0L, 0L),
...          education = c(23L, 26L, 22L, 18L),
...              black = c(10L, 12L, 9L, 9L),
...           hispanic = c(1L, 0L, 1L, 1L),
...            married = c(0L, 0L, 0L, 0L),
...           nodegree = c(0L, 0L, 0L, 0L),
...               re74 = c(1L, 0L, 1L, 1L),
...               re75 = c(1L, 0L, 0L, 0L)
... )
(¬_¬)df[df$re74==0 |df$re75==0, ]
treat age education black hispanic married nodegree re74 re75
2    2:   0        26    12        0       0        0    0    0
3    3:   0        22     9        1       0        0    1    0
4    4:   0        18     9        1       0        0    1    0

您可以从dplyr使用filter

library(dplyr)
df %>% filter(re74 == 0 | re75 == 0)

我们可以使用subset

subset(df, re74 == 0 | re75 == 0)

最新更新