这似乎是一个非常简单的问题,但无法在OS中找到解决方案(这不是重复的)。在dff
下面的示例中,我想提取在5和6(mn
值)中都常见的事件,即,在此示例中,如何提取dff
以仅Event2
在新数据帧中获取。
dff<-structure(list(ev = c("Event1", "Event1", "Event1", "Event1",
"Event1", "Event1", "Event1", "Event1", "Event1", "Event2", "Event2",
"Event2", "Event2", "Event2", "Event2", "Event2", "Event2", "Event2",
"Event2", "Event2", "Event3", "Event3", "Event3", "Event3"),
mn = c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6)), row.names = c(NA, -24L), class = c("tbl_df",
"tbl", "data.frame"))
dff
dff %>%
group_by(ev) %>%
filter(length(unique(mn)) > 1) %>%
unique()
或许
dff %>%
group_by(ev) %>%
summarise(chk = all(c(5, 6) %in% mn))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句