【发布时间】:2017-04-05 04:02:07
【问题描述】:
我遇到了一个有趣的过滤器问题。对于每个 TEI,我需要检查它是否存在于任何 CHILDREN_LIST 中,以及它是否删除了它存在的父行。
例如:TEI 611100 存在于 TEI 611000 的 CHILDREN_LIST 中,因此我需要删除 611000 行。
这是表格的 dput()。谢谢!
structure(list(TEI = c(611000L, 611100L, 238000L, 452000L, 561000L,
621000L, 622000L, 622100L, 623000L, 722000L, 722500L, 722510L
), OWNERSHIP = c(30L, 30L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L), RESULT = c(266.9, 259.5, 138, 103.3, 105.8, 130,
230, 214.1, 171.9, 204, 185.2, 185.2), CODE = c(3L, 4L, 3L, 3L,
3L, 3L, 3L, 4L, 3L, 3L, 4L, 5L), CHILDREN_LIST = structure(c(4L,
NA, 1L, 2L, 3L, 5L, 6L, NA, 7L, 8L, 9L, 10L), .Label = c("238100 238200 238300 238900",
"452100 452900", "561100 561200 561300 561400 561500 561600 561700 561900",
"611100 611200", "621100 621200 621300 621400 621500 621600 621900",
"622100 622200 622300", "623100 623200 623300 623900", "722300 722400 722500",
"722510", "722511 722513 722514 722515"), class = "factor"),
ESTIMATE_TYPE = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE), NAICS_LABEL = c(611, 6111,
238, 452, 561, 621, 622, 6221, 623, 722, 7225, 72251), NAICS_TITLE = structure(c(3L,
4L, 11L, 7L, 1L, 2L, 8L, 6L, 9L, 5L, 10L, 10L), .Label = c("Administrative and support services",
"Ambulatory health care services", "Educational services",
"Elementary and secondary schools", "Food services and drinking places",
"General medical and surgical hospitals", "General merchandise stores",
"Hospitals", "Nursing and residential care facilities", "Restaurants",
"Specialty trade contractors"), class = "factor")), .Names = c("TEI",
"OWNERSHIP", "RESULT", "CODE", "CHILDREN_LIST", "ESTIMATE_TYPE",
"NAICS_LABEL", "NAICS_TITLE"), row.names = c(NA, 12L), class = "data.frame")
【问题讨论】: