Skip to content

Data Science Tutorials

For Data Science Learners

  • Pattern Mining Analysis in R-With Examples R
  • Descriptive statistics vs Inferential statistics
    Descriptive statistics vs Inferential statistics: Guide Statistics
  • Calculate the P-Value from Chi-Square Statistic in R
    Calculate the P-Value from Chi-Square Statistic in R R
  • Extract patterns in R
    Extract patterns in R? R
  • How to Rank by Group in R?
    How to Rank by Group in R? R
  • How to Find the Size of a Data Frame in R R
  • How to Label Outliers in Boxplots in ggplot2
    How to Label Outliers in Boxplots in ggplot2? R
  • Error in rbind(deparse.level ...) numbers of columns of arguments do not match
    Error in rbind(deparse.level …) numbers of columns of arguments do not match R
How to Find Unmatched Records in R

How to Find Unmatched Records in R

Posted on June 20June 19 By Admin No Comments on How to Find Unmatched Records in R

How to Find Unmatched Records in R?, To retrieve all rows in one data frame that do not have matching values in another data frame, use the anti_join() function from the dplyr package in R.

What Is the Best Way to Filter by Date in R? – Data Science Tutorials

The following is the fundamental syntax for this function.

anti_join(df1, df2, by='col_name')

The examples below demonstrate how to utilise this syntax in practise.

How to make a rounded corner bar plot in R? – Data Science Tutorials

Example 1: Use anti join() with One Column

Let’s pretend we have the following two R data frames:

Now we  data frames

df1 <- data.frame(team=c('A', 'B', 'C', 'D', 'E'),
                  points=c(102, 104, 129, 224, 436))
df2 <- data.frame(team=c('A', 'B', 'C', 'F', 'G'),
                  points=c(412, 514, 519, 233, 117))

To return all rows in the first data frame that do not have a matching team in the second data frame, we can use the anti_join() function.

How to get the last value of each group in R – Data Science Tutorials

library(dplyr)

Using the ‘team’ column, execute an anti-join.

anti_join(df1, df2, by='team')
  team points
1    D    224
2    E    436

We can see that in the second data frame, there are exactly two teams from the first data frame that do not have a corresponding team name.

Example 2: Use anti_join() with Multiple Columns

Let’s pretend we have the following two R data frames.

Change ggplot2 Theme Color in R- Data Science Tutorials

Let’s create the data frames

df1 <- data.frame(team=c('A', 'A', 'A', 'B', 'B', 'B'),
                  position=c('G', 'G', 'F', 'G', 'F', 'C'),
                  points=c(182, 164, 159, 124, 136, 441))
df2 <- data.frame(team=c('A', 'A', 'A', 'B', 'B', 'B'),
                  position=c('G', 'G', 'C', 'G', 'F', 'F'),
                  points=c(152, 154, 159, 322, 217, 522))

The anti_join() method can be used to return all rows in the first data frame that do not match a team or position in the second data frame.

How to perform the Kruskal-Wallis test in R? – Data Science Tutorials

library(dplyr)

Use the ‘team’ and ‘position’ columns to do an anti-join.

anti_join(df1, df2, by=c('team', 'position'))
  team position points
1    A        F    159
2    B        C    441

We can see that in the second data frame, there are exactly two records from the first data frame that do not have a corresponding team name and position.

Check your inbox or spam folder to confirm your subscription.

R Tags:dplyr

Post navigation

Previous Post: How to Join Data Frames for different column names in R
Next Post: Create new variables from existing variables in R

Related Posts

  • Apply central limit throem in r
    Apply Central Limit Theorem in R R
  • Understanding Machine Learning and Data Science R
  • How to Standardize Data in R
    How to Standardize Data in R? R
  • display the last value of each line in ggplot
    How to add labels at the end of each line in ggplot2? R
  • Separate a data frame column into multiple columns
    Separate a data frame column into multiple columns-tidyr Part3 R
  • pheatmap function in R
    The pheatmap function in R R

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Best Prompt Engineering Books
  • Understanding Machine Learning and Data Science
  • Best Git Books
  • Top 5 Books to Learn Data Engineering
  • Mastering R Programming for Data Science: Tips and Tricks
  • About Us
  • Contact
  • Disclaimer
  • Privacy Policy

https://www.r-bloggers.com

  • YouTube
  • Twitter
  • Facebook
  • Course
  • Excel
  • Machine Learning
  • Opensesame
  • R
  • Statistics

Check your inbox or spam folder to confirm your subscription.

  • How to put margins on tables or arrays in R?
    How to put margins on tables or arrays in R? R
  • Number to Percentage in R
    Number to Percentage in R R
  • How to Specify Histogram Breaks in R R
  • Making games in R- Nara and eventloop Game Changers
    Making games in R- Nara and eventloop Game Changers Machine Learning
  • Sort or Order Rank in R R
  • Credit Card Fraud detection in R
    Credit Card Fraud Detection in R R
  • How to Use Gather Function in R
    How to Use Gather Function in R?-tidyr Part2 R
  • Extract values from vector in R: dplyr R

Privacy Policy

Copyright © 2025 Data Science Tutorials.

Powered by PressBook News WordPress theme