Join for unequal records in R

Asked

Viewed 79 times

2

I have two data frames called employees and employees.

nome.empregado <- c('Renato', 'Miguel', 'Paulo', 'Patrícia', 'Inês', 'Saulo', 
  'Diego', 'Maria', 'Jose', 'Julia', 'Tiago')
idade <- c(30, 31, 29, 30, 25, 30, 30, 35, 24, 31, 29)
empregados <- data.frame(nome.empregado, idade)

nome.empregado <- c('Renato', 'Miguel', 'Paulo', 'Patrícia', 'Inês', 'Saulo', 
  'Diego', 'Maria', 'Jose', 'Julia', 'Tiago','Carla')
idade <- c(30, 31, 29, 30, 25, 30, 30, 35, 24, 31, 29, 50)
funcionarios <- data.frame(nome.empregado, idade)

I need to make a Join to select only the unequal records. In my example above, I have to find only the line with the name Carla. I tried using the function merge and I couldn’t. I would like help for this problem. Thank you.

2 answers

3


Use the function anti_join package dplyr:

library(dplyr)
anti_join(funcionarios, empregados)

It will give a Warning message, but do not worry. It is irrelevant in this case.

0

From what I understand you don’t need Merge, only use a RIGTH JOIN for records that appear only in the right table, that is, the record of the left table will be null.

SELECT * FROM TableA TA
RIGHT JOIN TableB TB
    ON TA.NomeEmpregado = TB.NomeEmpregado
WHERE TA.NomeEmpregado IS NULL

Browser other questions tagged

You are not signed in. Login or sign up in order to post.