Different Records

4

I have two tables:

MATRICULA_A <-c(123,234,345,456)
dados_1 <- data.frame(MATRICULA_A)

MATRICULA_A <-c(345,456,111,222,333,444)
dados_2 <- data.frame(MATRICULA_A)

I need to extract only information from the dados_1 table that is different from dados_2 . In this example, I want to show, as a result, only the 123 and 234 registrations (% with%). I tried through dados_1 and did not.

    
asked by anonymous 23.11.2018 / 17:02

2 answers

6

I do not know how you used the anti_join function, but it worked here:

library(dplyr)
anti_join(dados_1,dados_2,by='MATRICULA_A') # 'MATRICULA_A' é a variável em comum

  MATRICULA_A
1         123
2         234
    
23.11.2018 / 17:13
3

In base R you can do this in several ways.

With setdiff :

setdiff(dados_1$MATRICULA_A, dados_2$MATRICULA_A)
#[1] 123 234

With %in% is more flexible, you can either get a vector as an object of class "data.frame" , such as the original df1 :

i <- !dados_1$MATRICULA_A %in% dados_2$MATRICULA_A

dados_1[i, ]
#[1] 123 234

dados_1[i, , drop = FALSE]
#  MATRICULA_A
#1         123
#2         234
    
23.11.2018 / 18:52