nest-mutate-joins | R Documentation |
Nested mutating joins add columns from y
to each of the nested data frames
in .nest_data
, matching observations based on the keys. There are four
nested mutating joins:
nest_inner_join()
only keeps observations from .nest_data
that have a
matching key in y
.
The most important property of an inner join is that unmatched rows in either input are not included in the result.
There are three outer joins that keep observations that appear in at least one of the data frames:
nest_left_join()
keeps all observations in .nest_data
.
nest_right_join()
keeps all observations in y
.
nest_full_join()
keeps all observations in .nest_data
and y
.
nest_inner_join( .data, .nest_data, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE ) nest_left_join( .data, .nest_data, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE ) nest_right_join( .data, .nest_data, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE ) nest_full_join( .data, .nest_data, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE )
.data |
A data frame, data frame extension (e.g., a tibble), or a lazy data frame (e.g., from dbplyr or dtplyr). |
.nest_data |
A list-column containing data frames |
y |
A data frame, data frame extension (e.g., a tibble), or a lazy data frame (e.g., from dbplyr or dtplyr). |
by |
A character vector of variables to join by or a join specification
created with If To join on different variables between the objects in To join by multiple variables, use a vector with length >1. For example,
To perform a cross-join, generating all combinations of each object in
|
copy |
If |
suffix |
If there are non-joined duplicate variables in |
... |
Other parameters passed onto methods. Includes:
|
keep |
Should the join keys from both |
nest_inner_join()
, nest_left_join()
, nest_right_join()
, and
nest_full_join()
are largely wrappers for dplyr::inner_join()
,
dplyr::left_join()
, dplyr::right_join()
, and dplyr::full_join()
and
maintain the functionality of these verbs within each nested data frame. For
more information on inner_join()
, left_join()
, right_join()
, or
full_join()
, please refer to the documentation in
dplyr
.
An object of the same type as .data
. Each object in the column .nest_data
will also be of the same type as the input. The order of the rows and columns
of each object in .nest_data
is preserved as much as possible. Each object
in .nest_data
has the following properties:
For nest_inner_join()
, a subset of rows in each object in .nest_data
.
For nest_left_join()
, all rows in each object in .nest_data
.
For nest_right_join()
, a subset of rows in each object in .nest_data
,
followed by unmatched y
rows.
For nest_full_join()
, all rows in each object in .nest_data
, followed
by unmatched y
rows.
Output columns include all columns from each .nest_data
and all non-key
columns from y
. If keep = TRUE
, the key columns from y
are included
as well.
If non-key columns in any object in .nest_data
and y
have the same name,
suffix
es are added to disambiguate. If keep = TRUE
and key columns in
.nest_data
and y
have the same name, suffix
es are added to
disambiguate these as well.
If keep = FALSE
, output columns included in by
are coerced to their
common type between the objects in .nest_data
and y
.
Groups are taken from .nest_data
.
Other joins:
nest-filter-joins
,
nest_nest_join()
gm_nest <- gapminder::gapminder %>% tidyr::nest(country_data = -continent) gm_codes <- gapminder::country_codes gm_nest %>% nest_inner_join(country_data, gm_codes, by = "country") gm_nest %>% nest_left_join(country_data, gm_codes, by = "country") gm_nest %>% nest_right_join(country_data, gm_codes, by = "country") gm_nest %>% nest_full_join(country_data, gm_codes, by = "country")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.