Help with full_join command

Hello,
I have a problem with de full_join command. I have two data frames for two rounds of an experiment. This is, in the first round, i have variables that start with r1_nameofvariable (and this is the first data frame), and in the second round i have the same variables that i have in the first dataframe, but they start with r2_nameofvariable.
I also have a variable that identifies de id of each person of the experiment (it is the same in both data frames).
I have to merge this 2 dataframes by de ID of each person. The result that I Want is:
id; r1_nameofvariable; r2_nameofvariable

Im using the full_join command, but the problem is that each observation (i.e each row of the dataframe from the first round) it is being duplicate when I use this command, when the only thing I want is to merge the columns using de ID variable (that is common for both dataframes).

An example:

I have the following dataframes:
Round 1:

#>  ID. r1_candidate. r1_sex.
#> 1           A        m                 
#> 2          B         m                   
#> 3          C         f                 
#> 4          D         m                 
#> 5          E         f                
#> 6          F         f               

Round 2:

#>  ID. r2_candidate. r2_sex.
#> 1           F        m                
#> 2          J         f                  
#> 3          Z         f                   
#> 4          Y         m                 
#> 5          Q         m             
  

What i want is to merge both dataframe (using the ID). Like the following:

#>  ID. r1_candidate. r1_sex. r2_candidate.r2_sex
#> 1           A        m                 F     m
#> 2          B         m                 j     f
#> 3          C         f                   Z     f
#> 4          D         m                Y      m
#> 5          E         f                  Q      m
#> 6          F         f                 NA      NA

The problem is that when I use the following command:

round_join <- full_join(round_1, round_2, by="ID")

I get the result, but the obsevation (each row of each dataframe) duplicates and i don't know why.

Please someone help me.

See the FAQ: How to do a minimal reproducible example reprex for beginners. With representative data (it doesn't have to be the full data, can be a built-in data set or even fake data), it's a relatively straight forward. Without, though, an answer is a tedious task.

I have the following dataframes:
Round 1:

#>  ID. r1_candidate. r1_sex.
#> 1           A        m                 
#> 2          B         m                   
#> 3          C         f                 
#> 4          D         m                 
#> 5          E         f                
#> 6          F         f               

Round 2:

#>  ID. r2_candidate. r2_sex.
#> 1           F        m                
#> 2          J         f                  
#> 3          Z         f                   
#> 4          Y         m                 
#> 5          Q         m             
  

What i want is to merge both dataframe (using the ID). Like the following:

#>  ID. r1_candidate. r1_sex. r2_candidate.r2_sex
#> 1           A        m                 F     m
#> 2          B         m                 j     f
#> 3          C         f                   Z     f
#> 4          D         m                Y      m
#> 5          E         f                  Q      m
#> 6          F         f                 NA      NA

The problem is that when I use the following command:

round_join <- full_join(round_1, round_2, by="ID")

I get the result, but the obsevation (each row of each dataframe) duplicates and i don't know why.

dat1 <- data.frame(
  ID = 1:5,
  r2_candidate =
    c("F", "J", "Z", "Y", "Q"),
  r2_sex =
    c("m", "f", "f", "m", "m"))

dat2 <- data.frame(
  ID =
    c(1, 2, 3, 4, 5, 6),
  r1_candidate =
    c("A", "B", "C", "D", "E", "F"),
  r1_sex =
    c("m", "m", "f", "m", "f", "f"),
  r2_candidater =
    c("F", "j", "Z", "Y", "Q", NA),
  "2_sex" =
    c("m", "f", "f", "m", "m", "N"))

dplyr::inner_join(dat1,dat2,by="ID")
#>   ID r2_candidate r2_sex r1_candidate r1_sex r2_candidater X2_sex
#> 1  1            F      m            A      m             F      m
#> 2  2            J      f            B      m             j      f
#> 3  3            Z      f            C      f             Z      f
#> 4  4            Y      m            D      m             Y      m
#> 5  5            Q      m            E      f             Q      m

This topic was automatically closed 21 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.