mutate_joins | R Documentation |
The mutating joins add columns from y
to x
, matching rows based on the keys:
inner_join()
: includes all rows in x
and y
.
left_join()
: includes all rows in x
.
right_join()
: includes all rows in y
.
full_join()
: includes all rows in x
or y
.
If a row in x
matches multiple rows in y
, all the rows in y
will be returned once for each matching row in x
.
inner_join(
x,
y,
by = NULL,
suffix = c(".x", ".y"),
...,
na_matches = c("na", "never")
)
left_join(
x,
y,
by = NULL,
suffix = c(".x", ".y"),
...,
keep = FALSE,
na_matches = c("na", "never")
)
right_join(
x,
y,
by = NULL,
suffix = c(".x", ".y"),
...,
keep = FALSE,
na_matches = c("na", "never")
)
full_join(
x,
y,
by = NULL,
suffix = c(".x", ".y"),
...,
keep = FALSE,
na_matches = c("na", "never")
)
x, y |
The |
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, To join by multiple variables, use a vector with length > 1. For example, To perform a cross-join, generating all combinations of |
suffix |
|
... |
Additional arguments to pass to |
na_matches |
Should The default, Use |
keep |
|
A data.frame
. The order of the rows and columns of x
is preserved as much as possible. The output has the
following properties:
For inner_join()
, a subset of x
rows.
For left_join()
, all x
rows.
For right_join()
, a subset of x
rows, followed by unmatched y
rows.
For full_join()
, all x
rows, followed by unmatched y
rows.
For all joins, rows will be duplicated if one or more rows in x
matches multiple rows in y
.
Output columns include all x
columns and all y
columns. If columns in x
and y
have the same name (and
aren't included in by
), suffix
es are added to disambiguate.
Output columns included in by
are coerced to common type across x
and y
.
Groups are taken from x
.
# If a row in `x` matches multiple rows in `y`, all the rows in `y` will be
# returned once for each matching row in `x`
df1 <- data.frame(x = 1:3)
df2 <- data.frame(x = c(1, 1, 2), y = c("first", "second", "third"))
df1 %>% left_join(df2)
# By default, NAs match other NAs so that there are two
# rows in the output of this join:
df1 <- data.frame(x = c(1, NA), y = 2)
df2 <- data.frame(x = c(1, NA), z = 3)
left_join(df1, df2)
# You can optionally request that NAs don't match, giving a
# a result that more closely resembles SQL joins
left_join(df1, df2, na_matches = "never")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.