我如何从不匹配的数据框中选择行? [英] How I can select rows from a dataframe that do not match?
问题描述
我正在尝试识别数据框中不符合的值,但无法确定如何执行此操作。 code>#make data frame
a < - data.frame(x = c(1,2,3,4))
b< - data.frame(y = c(1, 2,3,4,5,6))
#只选择不在'a'中的值
#尝试1:
results1< - b $ y [!a $ x]
#尝试2:
results2< - b [b $ y!= a $ x,]
如果 a = c(1,2,3)
c> a 是 b
的倍数。但是,我试图从数据框 y
中选择不在 x
中的所有值,以及不明白使用什么功能。
如果我理解正确,则需要否定%$ c $中的% c>运算符。这样做应该可以工作:
子集(b,!(%a $ x中的y%))
/ p>
>子集(b,!(y%in%a $ x))
y
5 5
6 6
I'm trying to identify the values in a data frame that do not match, but can't figure out how to do this.
# make data frame
a <- data.frame( x = c(1,2,3,4))
b <- data.frame( y = c(1,2,3,4,5,6))
# select only values from b that are not in 'a'
# attempt 1:
results1 <- b$y[ !a$x ]
# attempt 2:
results2 <- b[b$y != a$x,]
If a = c(1,2,3)
this works, as a
is a multiple of b
. However, I'm trying to just select all the values from data frame y
, that are not in x
, and don't understand what function to use.
If I understand correctly, you need the negation of the %in%
operator. Something like this should work:
subset(b, !(y %in% a$x))
> subset(b, !(y %in% a$x))
y
5 5
6 6
这篇关于我如何从不匹配的数据框中选择行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!