简体   繁体   English

如何基于R中不同数据框中的列值从一个数据框中删除行?

[英]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.

相关问题 R:从一个数据框中提取行,基于列名匹配另一个数据框中的值 - R: Extract Rows from One Data Frame, Based on Column Names Matching Values from Another Data Frame 当列与R中的其他数据框列匹配时,如何从数据框中删除行 - How to remove rows from a data frame when the column matches with a different data frame column in R R:根据文件名列从数据框中删除行 - R: Remove rows from data frame based on file name column R:根据多列中的值从数据框中删除行 - R: Remove rows from data frame based on values in several columns R如何根据列的第一个字符删除数据框中的行 - R how to remove rows in a data frame based on the first character of a column R:如何根据给定列的值删除数据框的行 - R: How to delete rows of a data frame based on the values of a given column 根据行数不同的另一个数据框的值将值分配给一个数据框的列 - Assign values to a column of one data frame based on values of another data frame with different number of rows 如何根据R中不同的列值删除行? - How to remove rows based on different column values in R? R:根据列表 2 的数据帧 [j] 的索引值从列表 1 的数据帧 [i] 中删除行 - R: Remove Rows From Data Frame [i] of List 1 based on Index values from Data Frame [j] of List 2 如何基于R中另一列的值从数据框中的一列提取值 - How to extract values from one column in a data frame based on values in another in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM