Find different values between numeric columns and identify them

Hi community

I'm have a data frame with two columns. I'm need compare them and find the values different between them.

DT_FULL have 20 rows, but the numeric (names) between columns is different. I'm need find which one are the different.

Im try with lef_join, inner_join. And case_when make a good approximation.

 DT_FULL <- data.frame(NAME_1= c(1,2,3,5,6,8,10,12,14,16,17,20,21,22,23,24,25,26,27,28),
                       NAME_2 = c(1:20))
 DT_FULL %>%
   mutate(SITUACION = case_when(NAME_1 == NAME_2 ~"IGUAL",
                           NAME_1 != NAME_2 ~"DIFERENTE", 
                           TRUE ~"NA"))
    NAME_1 NAME_2 SITUACION
1       1      1     IGUAL
2       2      2     IGUAL
3       3      3     IGUAL
4       5      4 DIFERENTE
5       6      5 DIFERENTE
6       8      6 DIFERENTE
7      10      7 DIFERENTE
8      12      8 DIFERENTE
9      14      9 DIFERENTE
10     16     10 DIFERENTE
11     17     11 DIFERENTE
12     20     12 DIFERENTE
13     21     13 DIFERENTE
14     22     14 DIFERENTE
15     23     15 DIFERENTE
16     24     16 DIFERENTE
17     25     17 DIFERENTE
18     26     18 DIFERENTE
19     27     19 DIFERENTE
20     28     20 DIFERENTE

But in this result for example in line 16, if you see NAME_2 is 16, but this number appear in other rows in NAME_1 . I'm need find this cases are equal for example.

Maybe I'm need compare between each cell but not all the column.

Im hope obtains something like that:
image

I think you want this information:

(numbers_that_are_in_both <- intersect(DT_FULL$NAME_1,
                                       DT_FULL$NAME_2))

(numbers_that_are_only_seen_once<- setdiff(unique(union(DT_FULL$NAME_1,
                                                DT_FULL$NAME_2)),intersect(DT_FULL$NAME_1,
                                       DT_FULL$NAME_2)))
1 Like

Tnks! , this make things that Im looking for.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.