joinDatasets {crunch} | R Documentation |
Add columns from one dataset to another, joining on a key
Description
As base::merge()
does for data.frame
s, this function takes two datasets,
matches rows based on a specified key variable, and adds columns from one to
the other.
Usage
joinDatasets(
x,
y,
by = intersect(names(x), names(y)),
by.x = by,
by.y = by,
all = FALSE,
all.x = TRUE,
all.y = FALSE,
copy = TRUE
)
extendDataset(
x,
y,
by = intersect(names(x), names(y)),
by.x = by,
by.y = by,
all = FALSE,
all.x = TRUE,
all.y = FALSE,
...
)
## S3 method for class 'CrunchDataset'
merge(
x,
y,
by = intersect(names(x), names(y)),
by.x = by,
by.y = by,
all = FALSE,
all.x = TRUE,
all.y = FALSE,
...
)
Arguments
x |
CrunchDataset to add data to |
y |
CrunchDataset to copy data from. May be filtered by rows and/or columns. |
by |
character, optional shortcut for specifying |
by.x |
CrunchVariable in |
by.y |
CrunchVariable in |
all |
logical: should all rows in x and y be kept, i.e. a "full outer"
join? Only |
all.x |
logical: should all rows in x be kept, i.e. a "left outer"
join? Only |
all.y |
logical: should all rows in y be kept, i.e. a "right outer"
join? Only |
copy |
logical: make a virtual or materialized join. Default is
|
... |
additional arguments, ignored |
Details
Since joining two datasets can sometimes produce unexpected results if the
keys differ between the two datasets, you may want to follow the
fork-edit-merge workflow for this operation. To do this, fork the dataset
with forkDataset()
, join the new data to the fork, ensure that
the resulting dataset is correct, and merge it back to the original dataset
with mergeFork()
. For more, see
vignette("fork-and-merge", package = "crunch")
.
Value
x
extended by the columns of y
, matched on the "by" variables.