簡體   English   中英

如何基於R中不同數據框中的列值從一個數據框中刪除行?

[英]How to remove rows from one dataframe based on the column values in a different data frame in R?

我有這個數據框1

數據框2

我想從數據框1中刪除具有數據框2中批處理編號的整行

決賽桌應如下所示:

使用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

數據:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM