We can merge two data frames in R by using the merge() function or by using family of join() function in dplyr package. The data frames must have same column names on which the merging happens. Merge() Function in R is similar to database join operation in SQL. The different arguments to merge() allow you to perform natural joins i.e. inner join, left join, right join,cross join, semi join, anti join and full outer join. We can perform Join in R using merge() Function or by using family of join() functions in dplyr package.
packages <- c("tidyverse", "fuzzyjoin")
packages <- lapply(packages, FUN = function(x) {
if(!require(x, character.only = TRUE)) {install.packages(x)
library(x, character.only = TRUE)}})
diamonds <- data.frame(diamonds)
match <- data_frame(match = c("^Idea", "mium", "Good"), type = 1:3)
With regular inner join, only Good <-> Good matches
inner.join <- diamonds %>% inner_join(match, by = c(cut = "match"))
nrow(inner.join)
With regular full join, only Good <-> Good matches
full.join <- diamonds %>% join(match, by = c(cut = "match"))
nrow(full.join)
With regular left join, only Good <-> Good matches
left.join <- diamonds %>% left_join(match, by = c(cut = "match"))
nrow(left.join)
With regular full join, only Good <-> Good matches
full.join <- diamonds %>% join(match, by = c(cut = "match"))
nrow(full.join)
With regular right join, only Good <-> Good matches
right.join <- diamonds %>% right_join(match, by = c(cut = "match"))
nrow(right.join)
inner.join.regex <- diamonds %>% regex_inner_join(match, by = c(cut = "match"))
nrow(inner.join.regex)
left.join <- regex_left_join(df, df.join, by = "join.column", ignore_case = FALSE)
right.join <- regex_right_join(df, df.join, by = "join.column", ignore_case = FALSE)