我试过用内置数据集重现这个问题,但它只发生在我自己的身上。
如果我们随机抽取我的数据子集:
structure(list(ID = structure(c(27L, 1L, 27L, 7L, 5L, 10L, 23L,
19L, 21L, 26L), .Label = c("AC ", "AJ ", "AT ", "AWY", "BP ",
"BW ", "CA ", "CK ", "CS ", "DJ ", "EN ", "ES ", "HF ", "HG ",
"HL ", "HR ", "IP ", "JA ", "JG ", "JN ", "KB ", "KP ", "MJ ",
"PC ", "RFH", "RPA", "SB ", "SG ", "TM "), class = "factor"),
TNO = c(30L, 60L, 30L, 10000L, 10000L, 10000L, 120L, 60L,
120L, 10000L), TNOGroup = structure(c(1L, 1L, 1L, 2L, 2L,
2L, 2L, 1L, 2L, 2L), .Label = c("Good", "Poor"), class = "factor"),
x = c(6.15, 7.75, 5.6, 3.05, 3, 4.1, 6, 3.9, 5.85, 3.75),
View = structure(c(1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L
), .Label = c("Binocular", "Monocular"), class = "factor"),
Prior = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L
), .Label = c("N", "Y"), class = "factor")), .Names = c("ID",
"TNO", "TNOGroup", "x", "View", "Prior"), row.names = c(169L,
49L, 24L, 16L, 9L, 4L, 35L, 18L, 164L, 36L), class = "data.frame")
然后尝试删除 ID 的所有实例,该 ID 是两个字符的字符串,例如“SB”:
data2 <- data[!data$ID %in% c("SB"),] # List syntax in case multiple cases
但是,当我检查数据框时,ID 为“SB”的案例仍然存在。当我尝试使用诸如“RPA”之类的三个字符的字符串时,所有具有此 ID 的案例都将按预期删除。
关于为什么会发生这种情况的任何见解?