[英]Filter according to two conditions and a category in R
一種方法是在過濾后與自身進行left_join
。
library(dplyr)
dat |>
filter(Index == "Bl", Document == "b") |>
select(Category) |>
left_join(dat)
+ Joining, by = "Category"
Category Score Index Document
1 Pepe 5 Al a
2 Pepe 1 Bl b
3 Mikel 1 Cl a
4 Mikel 6 Bl b
幾個選項:
基地 R -
subset(dat, Category %in% Category[Index == "Bl" & Document == "b"])
# Category Score Index Document
#1 Pepe 5 Al a
#2 Pepe 1 Bl b
#5 Mikel 1 Cl a
#6 Mikel 6 Bl b
dplyr
-
library(dplyr)
dat %>%
group_by(Category) %>%
filter(any(Index == "Bl" & Document == "b")) %>%
ungroup()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.