nest_nest_join()
returns all rows and columns in .nest_data
with a new
nested-df column that contains all matches from y
. When there is no match,
the list contains a 0-row tibble.
Usage
nest_nest_join(
.data,
.nest_data,
y,
by = NULL,
copy = FALSE,
keep = FALSE,
name = NULL,
...
)
Arguments
- .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
join_by()
.If
NULL
, the default,nest_*_join()
will perform a natural join, using all variables in common across each object in.nest_data
andy
. A message lists the variables so you can check they're correct; suppress the message by supplyingby
explicitly.To join on different variables between the objects in
.nest_data
andy
, use a named vector. For example,by = c("a" = "b")
will match.nest_data$a
toy$b
for each object in.nest_data
.To join by multiple variables, use a vector with length >1. For example,
by = c("a", "b")
will match.nest_data$a
toy$a
and.nest_data$b
toy$b
for each object in.nest_data
. Use a named vector to match different variables in.nest_data
andy
. For example,by = c("a" = "b", "c" = "d")
will match.nest_data$a
toy$b
and.nest_data$c
toy$d
for each object in.nest_data
.To perform a cross-join, generating all combinations of each object in
.nest_data
andy
, useby = character()
.- copy
If
.nest_data
andy
are not from the same data source andcopy = TRUE
theny
will be copied into the same src as.nest_data
. (Need to review this parameter in more detail for applicability with nplyr)- keep
Should the join keys from both
.nest_data
andy
be preserved in the output?- name
The name of the list column nesting joins create. If
NULL
, the name ofy
is used.- ...
One or more unquoted expressions separated by commas. Variable names can be used if they were positions in the data frame, so expressions like
x:y
can be used to select a range of variables.
Value
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.
Details
nest_nest_join()
is largely a wrapper around dplyr::nest_join()
and
maintains the functionality of nest_join()
within east nested data frame.
For more information on nest_join()
, please refer to the documentation in
dplyr
.
See also
Other joins:
nest-filter-joins
,
nest-mutate-joins
Examples
gm_nest <- gapminder::gapminder %>% tidyr::nest(country_data = -continent)
gm_codes <- gapminder::country_codes
gm_nest %>% nest_nest_join(country_data, gm_codes, by = "country")
#> # A tibble: 5 × 2
#> continent country_data
#> <fct> <list>
#> 1 Asia <tibble [396 × 6]>
#> 2 Europe <tibble [360 × 6]>
#> 3 Africa <tibble [624 × 6]>
#> 4 Americas <tibble [300 × 6]>
#> 5 Oceania <tibble [24 × 6]>