Skip to content

Data Science Tutorials

  • Home
  • R
  • Statistics
  • Course
  • Machine Learning
  • Guest Blog
  • Contact
  • About Us
  • Toggle search form
  • How to perform kruskal wallis test in r
    How to perform the Kruskal-Wallis test in R? R
  • How do augmented analytics work
    How do augmented analytics work? R
  • Dealing Missing values in R
    Dealing With Missing values in R R
  • How to Add a title to ggplot2 Plots in R
    How to Add a caption to ggplot2 Plots in R? R
  • Statistical test assumptions and requirements
    Statistical test assumptions and requirements Statistics
  • how to create a hexbins chart in R
    How to create a hexbin chart in R R
  • Separate a data frame column into multiple columns
    Separate a data frame column into multiple columns-tidyr Part3 R
  • Select the First Row by Group in R
    Select the First Row by Group in R R
How to Find Unmatched Records in R

How to Find Unmatched Records in R

Posted on June 20June 19 By Jim No Comments on How to Find Unmatched Records in R
Tweet
Share
Share
Pin

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.

Tweet
Share
Share
Pin
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

  • Convert multiple columns into a single column
    Convert multiple columns into a single column-tidyr Part4 R
  • Box Cox transformation in R
    Box Cox transformation in R R
  • R Percentage by Group Calculation
    R Percentage by Group Calculation R
  • Interactive 3d plot in R
    Interactive 3d plot in R-Quick Guide R
  • Error in solve.default(mat)  Lapack routine dgesv system is exactly singular
    Error in solve.default(mat) :  Lapack routine dgesv: system is exactly singular: U[2,2] = 0 R
  • Calculate the P-Value from Chi-Square Statistic in R
    Calculate the P-Value from Chi-Square Statistic in R R

Leave a Reply Cancel reply

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

  • About Us
  • Contact
  • Disclaimer
  • Guest Blog
  • Privacy Policy
  • YouTube
  • Twitter
  • Facebook
  • Defensive Programming Strategies in R
  • Plot categorical data in R
  • Top Data Modeling Tools for 2023
  • Ogive Graph in R
  • Is R or Python Better for Data Science in Bangalore

Check your inbox or spam folder to confirm your subscription.

  • Data Scientist Career Path Map in Finance
  • Is Python the ideal language for machine learning
  • Convert character string to name class object
  • How to play sound at end of R Script
  • Pattern Searching in R
  • How to compare variances in R
    How to compare variances in R R
  • Statistical test assumptions and requirements
    Statistical test assumptions and requirements Statistics
  • How to convert characters from upper to lower case in R
    How to convert characters from upper to lower case in R? R
  • The Multinomial Distribution in R
    The Multinomial Distribution in R R
  • Crosstab calculation in R
    Crosstab calculation in R R
  • How to Standardize Data in R
    How to Standardize Data in R? R
  • How to Join Data Frames for different column names in R
    How to Join Data Frames for different column names in R R
  • Best Data Science YouTube Tutorials
    Best Data Science YouTube Tutorials Free to Learn Course

Copyright © 2023 Data Science Tutorials.

Powered by PressBook News WordPress theme