匹配R中的值[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

说,我有数据集

mydat=structure(list(x1 = structure(c(2L, 3L, 4L, 5L, 1L), .Label = c("", 
"a", "b", "c", "d"), class = "factor"), x2 = structure(1:5, .Label = c("a", 
"b", "c", "d", "e"), class = "factor")), .Names = c("x1", "x2"
), class = "data.frame", row.names = c(NA, -5L))

x1 has values a,b,c,d
x2 has values a,b,c,d,e

如何显示x2 var中的值,但x1中没有?在我们的例子中,这是e

作为我想要的输出

    Value
1   e

如果这个问题重复,请告诉我,我会删除它。

r dataframe dplyr
1个回答
1
投票

我们可以尝试

setdiff(mydat$x2,mydat$x1)
[1] "e"
© www.soinside.com 2019 - 2024. All rights reserved.