nest_join | R Documentation |
A nest join leaves x
almost unchanged, except that it adds a new
list-column, where each element contains the rows from y
that match the
corresponding row in x
.
nest_join(x, y, by = NULL, copy = FALSE, keep = NULL, name = NULL, ...)
## S3 method for class 'data.frame'
nest_join(
x,
y,
by = NULL,
copy = FALSE,
keep = NULL,
name = NULL,
...,
na_matches = c("na", "never"),
unmatched = "drop"
)
x , y |
A pair of data frames, data frame extensions (e.g. a tibble), or lazy data frames (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
by |
A join specification created with If To join on different variables between To join by multiple variables, use a
For simple equality joins, you can alternatively specify a character vector
of variable names to join by. For example, To perform a cross-join, generating all combinations of |
copy |
If |
keep |
Should the new list-column contain join keys? The default will preserve the join keys for inequality joins. |
name |
The name of the list-column created by the join. If |
... |
Other parameters passed onto methods. |
na_matches |
Should two
|
unmatched |
How should unmatched keys that would result in dropped rows be handled?
|
The output:
Is same type as x
(including having the same groups).
Has exactly the same number of rows as x
.
Contains all the columns of x
in the same order with the same values.
They are only modified (slightly) if keep = FALSE
, when columns listed
in by
will be coerced to their common type across x
and y
.
Gains one new column called {name}
on the far right, a list column
containing data frames the same type as y
.
You can recreate many other joins from the result of a nest join:
inner_join()
is a nest_join()
plus tidyr::unnest()
.
left_join()
is a nest_join()
plus tidyr::unnest(keep_empty = TRUE)
.
semi_join()
is a nest_join()
plus a filter()
where you check
that every element of data has at least one row.
anti_join()
is a nest_join()
plus a filter()
where you check that every
element has zero rows.
This function is a generic, which means that packages can provide implementations (methods) for other classes. See the documentation of individual methods for extra arguments and differences in behaviour.
The following methods are currently available in loaded packages: \Sexpr[stage=render,results=rd]{dplyr:::methods_rd("nest_join")}.
Other joins:
cross_join()
,
filter-joins
,
mutate-joins
df1 <- tibble(x = 1:3)
df2 <- tibble(x = c(2, 3, 3), y = c("a", "b", "c"))
out <- nest_join(df1, df2)
out
out$df2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.