R/pick_recensus.R
pick_recensus.RdBased on a reference dataset x, this function helps you
identify stems that remain to be recensused in a dataset y. This
function does the same work as dplyr::anti_join(). The only difference is
that the signature of pick_recensus() is a little simpler (irrelevant
arguments hidden via ...) to focus your attention on the arguments that are
most useful in helping you identify stems to recensus. This function also
exists to help you discover the *join() functions of dplyr, which will
help you solve more general problems.
pick_recensus(x, y, by = NULL, ...)
| x, y | Dataframes to join:
|
|---|---|
| by | a character vector of variables to join by. If To join by different variables on x and y use a named vector.
For example, |
| ... | Other parameters passed onto dplyr::anti_join. |
Returns all rows from x where there are not matching values in
y, keeping just columns from x.
This function preserves dplyr's style and thus non-standard evaluation. If you want to use it inside your own functions, you should learn about tidy eval (implemented via the rlang package). A good place to start is at dplyr's website.
x <- tibble::tribble( ~unique_stem, ~quadrat, "01_1", "001", "02_1", "001", "02_2", "001", "04_1", "002", "04_2", "002", "05_1", "002" ) y <- tibble::tribble( ~unique_stem, "01_1", "02_2", "04_2" ) pick_recensus(x, y)#>#> # A tibble: 3 x 2 #> unique_stem quadrat #> <chr> <chr> #> 1 02_1 001 #> 2 04_1 002 #> 3 05_1 002# Same pick_recensus(x, y, by = "unique_stem")#> # A tibble: 3 x 2 #> unique_stem quadrat #> <chr> <chr> #> 1 02_1 001 #> 2 04_1 002 #> 3 05_1 002y2 <- dplyr::tribble( ~unq_stem, "01_1", "02_2", "04_2" ) pick_recensus(x, y2, by = c("unique_stem" = "unq_stem"))#> # A tibble: 3 x 2 #> unique_stem quadrat #> <chr> <chr> #> 1 02_1 001 #> 2 04_1 002 #> 3 05_1 002# For this and more general problems you can use `dplyr::*_join()` functions dplyr::anti_join(x, y2, by = c("unique_stem" = "unq_stem"))#> # A tibble: 3 x 2 #> unique_stem quadrat #> <chr> <chr> #> 1 02_1 001 #> 2 04_1 002 #> 3 05_1 002