tidyverse
library(dplyr)
anti_join(supply, codes, by = c("state", "codetype", "code"))
# state codetype code codetitle
# 1 34 15 123459 Something_4
碱基R
codes$code_rn <- seq_len(nrow(codes))
supply$supply_rn <- seq_len(nrow(supply))
temp <- merge(codes, supply, by = c("state", "codetype", "code"))
temp
# state codetype code codetitle.x code_rn codetitle.y supply_rn
# 1 32 15 123455 Something_Else 2 Something_3 2
# 2 32 15 123456 Something 1 Something_2 1
supply[ !supply$supply_rn %in% temp$supply_rn, ]
# state codetype code codetitle supply_rn
# 3 34 15 123459 Something_4 3
(和一些列清理)
替代碱基R
这实际上是您开始的内容:
supply_id <- with(supply, paste(state, codetype, code, sep = "|"))
supply_id
# [1] "32 15 123456" "32 15 123455" "34 15 123459"
codes_id <- with(codes, paste(state, codetype, code, sep = "|"))
codes_in
# [1] "32|15|123456" "32|15|123455" "32|10|123455"
supply[!supply_id %in% codes_id,]
# state codetype code codetitle supply_rn
# 3 34 15 123459 Something_4 3
数据
codes <- read.table(header = TRUE, text="
state codetype code codetitle
32 15 123456 Something
32 15 123455 Something_Else
32 10 123455 Something_Else")
supply <- read.table(header = TRUE, text="
state codetype code codetitle
32 15 123456 Something_2
32 15 123455 Something_3
34 15 123459 Something_4")