statar (version 0.4.0)

join: Join two data frames together

Description

Join two data frames together

Usage

join(x, y, kind, on = intersect(names(x), names(y)), suffixes = c(".x",
  ".y"), check = m ~ m, gen = FALSE, inplace = FALSE, update = FALSE,
  type)

Arguments

x
The master data.frame
y
The using data.frame
kind
The kind of (SQL) join among "full" (default), "left", "right", "inner", "semi", "anti" and "cross".
on
Character vectors specifying variables to match on. Default to common names between x and y.
suffixes
A character vector of length 2 specifying suffix of overlapping columns. Defaut to ".x" and ".y".
check
A formula checking for the presence of duplicates. Specifying 1~m (resp m~1, 1~1) checks that joined variables uniquely identify observations in x (resp y, both).
gen
Name of new variable to mark result, or the boolean FALSE (default) if no such variable should be created. The variable equals 1 for rows in master only, 2 for rows in using only, 3 for matched rows.
inplace
A boolean. In case "kind"= "left" and RHS of check is 1, the merge can be one in-place.
update
A boolean. For common variables in x and y not specified in "on", replace missing observations by the non missing observations in y.
type
Deprecated

Value

  • A data.frame that joins rows in master and using datases. Importantly, if x or y are not keyed, the join may change their row orders.

Examples

Run this code
library(dplyr)
x <- data.frame(a = rep(1:2, each = 3), b=1:6)
y <- data.frame(a = 0:1, bb = 10:11)
join(x, y, kind = "full")
join(x, y, kind = "left", gen = "_merge")
join(x, y, kind = "right", gen = "_merge")
join(x, y, kind = "inner", check = m~1)
join(x, y, kind = "semi")
join(x, y, kind = "anti")
y <- rename(y, b = bb)
join(x, y, kind = "full", on = "a")
join(x, y, kind = "full", on = "a", suffixes = c("",".i"))
y <- data.frame(a = 0:1, bb = 10:11)
join(x, y, kind = "left", check = m~1)
x <- data.frame(a = c(1,2), b=c(NA, 2))
y <- data.frame(a = c(1,2), b = 10:11)
join(x, y, kind = "left", on = "a",  update = TRUE)
join(x, y, kind = "left", on = "a", check = m~1,  update = TRUE)

Run the code above in your browser using DataCamp Workspace