Join for unequal records in R

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 join to select only the unequal records. In my example above, I have to find just the line with the name Carla. I tried using the merge function and could not. I would like help for this problem. Thank you.

    
asked by anonymous 28.12.2017 / 20:40

2 answers

3

Use the anti_join function of the dplyr package:

library(dplyr)
anti_join(funcionarios, empregados)

It will give a warning message, but do not worry. It's irrelevant in this case.

    
28.12.2017 / 22:33
0

So I understand you do not need Merge , just use a RIGTH JOIN for the records that appear only in the right table, left will be null.

SELECT * FROM TableA TA
RIGHT JOIN TableB TB
    ON TA.NomeEmpregado = TB.NomeEmpregado
WHERE TA.NomeEmpregado IS NULL
    
28.12.2017 / 20:49