EM1PRI EM1PRIEM2PRIEM3PRIEM3PRI
我不知道我是否搜索问题不正确,因为这是一个棘手的解释,但到目前为止我还没有在网上找到任何答案!基本上我有两个数据框,DF1有120行,DF2有22000行。它们都有"查找"功能。基于来自其他三个列的值。它们看起来像这样(一个子集):
DF1:
查找th>一种方法是对两个数据帧中的每个Lookup
值使用行号,然后连接Lookup
值和行号。
library(dplyr)
df1 %>%
group_by(Lookup) %>%
mutate(rn = row_number()) %>%
left_join(df2 %>%
group_by(Lookup) %>%
mutate(rn = row_number())) %>%
dplyr::select(-rn)
Lookup ID
<chr> <dbl>
1 EM1PRI 14567
2 EM1PRI 12345
3 EM2PRI 16789
4 EM3PRI NA
5 EM3PRI NA
df1 <- structure(list(Lookup = c("EM1PRI", "EM1PRI", "EM2PRI", "EM3PRI",
"EM3PRI")), class = "data.frame", row.names = c(NA, -5L))
df2 <- structure(list(Lookup = c("EM1PRI", "EM1PRI", "EM1PRI", "EM1PRI",
"EM2PRI", "WM1PRI"), ID = c(14567, 12345, 13456, 15678, 16789,
17890)), class = "data.frame", row.names = c(NA, -6L))