[英]How to remove rows from one dataframe based on the column values in a different data frame in R?
I have this dataframe 1 我有这个数据框1
Data frame 2 数据框2
I would want to remove the entire rows from Data Frame 1 with the batch NO.s in Data frame 2 我想从数据框1中删除具有数据框2中批处理编号的整行
Final table should look like: 决赛桌应如下所示:
Using anti_join
, which basically keeps only the rows in df1
not in df2
: 使用
anti_join
,基本上只保留df1
中的行,而不保留df2
的行:
library(dplpyr)
df1 %>%
anti_join(df2, by = "BatchNo.")
# Joining, by = "BatchNo." # be sure that "BatchNo." is spelled the same
# Month Place BatchNo. Passed
# 1 MAR CAN 14824 N
# 2 OCT GER 15842 Y
# 3 JUL POR 13654 N
Data: 数据:
tt <- "Month Place BatchNo. Passed
FEB NZ 12451 Y
MAR CAN 14824 N
OCT GER 15842 Y
JUL POR 13654 N
MAY ESP 12445 N"
df1 <- read.table(text=tt, header = T)
tt <- "BatchNo. Commodity Price
12451 BUS 100
12445 CAR 200"
df2 <- read.table(text=tt, header = T)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.