【问题标题】:To find diff between 2 vectors查找 2 个向量之间的差异
【发布时间】:2017-09-29 14:37:28
【问题描述】:

要查找 2 个向量之间的差异 - 提到的答案之一是:

x[is.na(match(x,y))]

x <- c(1,2,3,4); y <- c(2,3,4

有人可以详细解释一下这个答案吗?

【问题讨论】:

  • 这里 x 和 y 是 - x

标签: r match set-difference


【解决方案1】:

只需将其分解为步骤,

match(x,y)           #If no match is found, it returns (by default) NA
#[1] NA  1  2  3

is.na(match(x,y))    #Thus, is.na will create a logical vector for NA values
#[1]  TRUE FALSE FALSE FALSE

x[is.na(match(x,y))]    #Using the above logical vector as index for x
#[1] 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 2011-07-29
    • 2016-03-20
    • 1970-01-01
    相关资源
    最近更新 更多