R语言semi_join()和anti_join()

Filtering joins filter rows from x based on the presence or absence of matches in y:

semi_join() return all rows from x with a match in y.

anti_join() return all rows from x without a match in y.

# "Filtering" joins keep cases from the LHS
band_members %>% semi_join(band_instruments)
#> Joining, by = "name"
#> # A tibble: 2 x 2
#>   name  band   
#>   <chr> <chr>  
#> 1 John  Beatles
#> 2 Paul  Beatles
band_members %>% anti_join(band_instruments)
#> Joining, by = "name"
#> # A tibble: 1 x 2
#>   name  band  
#>   <chr> <chr> 
#> 1 Mick  Stones

semi_join只返回x表格中中可以跟y表格匹配的行,anti_join返回x表格中与y表格不匹配的行。

原文地址:https://www.cnblogs.com/yaos/p/14014130.html