| join {m61r} | R Documentation |
Join two data.frames
Description
Join two data.frames.
Usage
left_join_(df, df2, by = NULL, by.x = NULL, by.y = NULL)
anti_join_(df, df2, by = NULL, by.x = NULL, by.y = NULL)
full_join_(df, df2, by = NULL, by.x = NULL, by.y = NULL)
inner_join_(df, df2, by = NULL, by.x = NULL, by.y = NULL)
right_join_(df, df2, by = NULL, by.x = NULL, by.y = NULL)
semi_join_(df, df2, by = NULL, by.x = NULL, by.y = NULL)
Arguments
df |
data.frame |
df2 |
data.frame |
by |
column names of the pivot of both data.frame 1 and data.frame 2 if they are identical. Otherwise, better to use by.x and by.y |
by.x |
column names of the pivot of data.frame 1 |
by.y |
column names of the pivot of data.frame 2 |
Value
The functions return a data frame. The output has the following properties:
-
For functions
left_join(),inner_join(),full_join(), andright_join(), output includes alldf1columns and alldf2columns. For columns with identical names indf1anddf2, a suffix '.x' and '.y' is added. Forleft_join(), alldf1rows with matching rows ofdf2Forinner_join(), a subset ofdf1rows matching rows ofdf2. Forfull_join(), alldf1rows, with alldf2rows. Forright_join(), alldf2rows with matching rows ofdf1. -
For functions
semi_join()andanti_join(), output include columns ofdf1only. Forsemi_join(), alldf1rows with a match indf2. Foranti_join(), a subset ofdf1rows not matching rows ofdf2.
Examples
books <- data.frame(
name = I(c("Tukey", "Venables", "Tierney","Ripley",
"Ripley", "McNeil", "R Core")),
title = c("Exploratory Data Analysis",
"Modern Applied Statistics ...",
"LISP-STAT",
"Spatial Statistics", "Stochastic Simulation",
"Interactive Data Analysis",
"An Introduction to R"),
other.author = c(NA, "Ripley", NA, NA, NA, NA,"Venables & Smith"))
authors <- data.frame(
surname = I(c("Tukey", "Venables", "Tierney", "Ripley", "McNeil","Asimov")),
nationality = c("US", "Australia", "US", "UK", "Australia","US"),
deceased = c("yes", rep("no", 4),"yes"))
tmp <- left_join_(books,authors, by.x = "name", by.y = "surname")
head(tmp)
tmp <- inner_join_(books,authors, by.x = "name", by.y = "surname")
head(tmp)
tmp <- full_join_(books,authors, by.x = "name", by.y = "surname")
head(tmp)
tmp <- right_join_(books,authors, by.x = "name", by.y = "surname")
head(tmp)
tmp <- semi_join_(books,authors, by.x = "name", by.y = "surname")
head(tmp)
tmp <- anti_join_(books,authors, by.x = "name", by.y = "surname")
head(tmp)