提供第一个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))
它看起来是这样的:
chromosome positon
1A 12
1A 13
2A 12
2A 14
3A 15
3A 16
第二个数据帧:
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))
它看起来是这样的:
chromosome positon rs
3A 16 hauwei
3A 15 tigre
2A 12 obregon
2A 14 verde
1A 12 jaz
1A 13 okla
请注意,两个数据框中的“位置”列都有重复的值,但是“染色体”和“位置”列的组合是唯一的。我的疑问是,在这种情况下,数据帧确实具有重复的值,如何将df2
中的列'rs'添加到df1
中。