【问题标题】:What is the R equivalent of the "except" function?\"except\" 函数的 R 等价物是什么?
【发布时间】:2023-01-17 12:07:50
【问题描述】:

我有两个数据集 df1 和 df2,它们具有相同的列数和相同的标题。我想删除 df1 中也存在于 df2 中的所有行。在 SQL 中,我会使用 except 函数。 df1 除了 df2。

R 中 except 的等价物是什么?

df1:

cust_id
1
2
3

df2

cust_id
1
2

df1 except df2 将导致:

cust_id
3

【问题讨论】:

    标签: r dplyr


    【解决方案1】:

    你可以使用setdiff

    df1 <- setdiff(df1, df2)
    
    df1
    #>   cust_id
    #> 1       3
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 2018-11-13
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 2018-06-30
      相关资源
      最近更新 更多