merge | R Documentation |
Merge two dbi.table
s. By default, the columns to merge on are
determined by the first of the following cases to apply.
If x
and y
are each unmodified dbi.table
s in
the same dbi.catalog
and if there is a single foreign key
relating x
and y
(either x
referencing
y
, or y
referencing x
), then it is used to set
by.x
and by.y
.
If x
and y
have shared key columns, then they are
used to set by
(that is,
by = intersect(key(x), key(y))
when
intersect(key(x), key(y))
has length greater than zero).
If x
has a key, then it is used to set by
(that is,
by = key(x)
when key(x)
has length greater than
zero).
If x
and y
have columns in common, then they are used
to set
by
(that is, by = intersect(names(x), names(y))
when
intersect(names(x), names(y))
has length greater than zero).
Use the by
, by.x
, and by.y
arguments explicitly to
override this default.
## S3 method for class 'dbi.table'
merge(
x,
y,
by = NULL,
by.x = NULL,
by.y = NULL,
all = FALSE,
all.x = all,
all.y = all,
sort = TRUE,
suffixes = c(".x", ".y"),
no.dups = TRUE,
recursive = FALSE,
...
)
x , y |
|
by |
a character vector of shared column names in |
by.x , by.y |
character vectors of column names in |
all |
a logical value. |
all.x |
a logical value. When |
all.y |
a logical value. Analogous to |
sort |
a logical value. When TRUE (default), the key of the merged
|
suffixes |
a length-2 character vector. The suffixes to be used for making
non- |
no.dups |
a logical value. When |
recursive |
a logical value. Only used when |
... |
additional arguments are passed to |
merge.dbi.table
uses sql.join
to join x
and
y
then formats the result set to match the typical merge
output.
a dbi.table
.
merge.data.table
,
merge.data.frame
chinook <- dbi.catalog(chinook.duckdb)
#The Album table has a foreign key constriant that references Artist
merge(chinook$main$Album, chinook$main$Artist)
#When y is omitted, x's foreign key relationship is used to determine y
merge(chinook$main$Album)
#Track has 3 foreign keys: merge with Album, Genre, and MediaType
merge(chinook$main$Track)
#Track references Album but not Artist, Album references Artist
#This dbi.table includes the artist name
merge(chinook$main$Track, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.