SasJoin: Join (merge) two data frames

Description Usage Arguments Value Examples

View source: R/SasJoin.R

Description

Join (merge) two data frames

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
SasJoin(
  x,
  y,
  by = intersect(names(x), names(y)),
  xLast = TRUE,
  yLast = TRUE,
  xAll = TRUE,
  yAll = TRUE,
  doSort = TRUE
)

Arguments

x

data frame

y

data frame

by

column names

xLast

Whether to reuse rows of x

yLast

Whether to reuse rows of y

xAll

Whether to match all rows of x by adding NAs

yAll

Whether to match all rows of y by adding NAs

doSort

Whether to sort on the by columns

Value

data frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
x <- data.frame(ABC = c("A", "A", "A", "B", "B", "B", "B", "C", "C"), 
                OneTwo = c(1, 1, 1, 1, 1, 2, 1, 1, 1), 
                x = 10 * (1:9), stringsAsFactors = FALSE)
y <- data.frame(ABC = c("A", "A", "A", "B", "C", "C"), 
                OneTwo = c(1, 1, 2, 1, 1, 2), 
                y = 101:106, stringsAsFactors = FALSE)
x
y                 

# Inner join
SasJoin(x, y, xLast = FALSE, yLast = FALSE, xAll = FALSE, yAll = FALSE)

# Left join
SasJoin(x, y, xLast = FALSE, yLast = FALSE, xAll = TRUE, yAll = FALSE)

# Left join by reusing rows of y when possible
SasJoin(x, y, xLast = FALSE, yLast = TRUE, xAll = TRUE, yAll = FALSE)

# Reusing rows of y when possible but not a full left join
SasJoin(x, y, xLast = FALSE, yLast = TRUE, xAll = FALSE, yAll = FALSE)

# Reusing rows of both x and y
SasJoin(x, y, xLast = TRUE, yLast = TRUE, xAll = FALSE, yAll = FALSE)

# Outer join by reusing rows of both x and y
SasJoin(x, y, xLast = TRUE, yLast = TRUE, xAll = TRUE, yAll = TRUE)

# Outer join without reusing rows
SasJoin(x, y, xLast = FALSE, yLast = FALSE, xAll = TRUE, yAll = TRUE)

olangsrud/experimentalRpackage documentation built on Sept. 20, 2021, 10:32 p.m.