0

Giving the first df:

df1 <- structure(list(chromosome = structure(c(1L, 1L, 2L, 2L, 3L, 3L
), .Label = c("1A", "2A", "3A"), class = "factor"), positon = c(12, 
13, 12, 14, 15, 16)), class = "data.frame", row.names = c(NA,-6L))

It looks this way:

 chromosome positon
     1A      12
     1A      13
     2A      12
     2A      14
     3A      15
     3A      16

And the second dataframe :

df2 <- structure(list(chromosome = structure(c(3L, 3L, 2L, 2L, 1L, 1L
), .Label = c("1A", "2A", "3A"), class = "factor"), positon = c(16, 
15, 12, 14, 12, 13), rs = structure(c(1L, 5L, 3L, 6L, 2L, 4L), .Label = 
c("hauwei", "jaz", "obregon", "okla", "tigre", "verde"), class = 
"factor")), class = "data.frame", row.names = c(NA, -6L))

It looks this way:

chromosome positon  rs
     3A      16  hauwei
     3A      15   tigre
     2A      12 obregon
     2A      14   verde
     1A      12     jaz
     1A      13    okla

Please note that the column 'position' in both dataframes have duplicated values, however the combination of columns 'chromosome' and 'position' is unique. My doubt is how to add the column 'rs' from df2 into df1 in an ordered manner in this case which a dataframe does have duplicated values.

moth
  • 1,833
  • 12
  • 29

0 Answers0