这是我的数据框示例。而且我想将结果按列A(colA)分组,然后过滤仅同时具有以下4种类型的值的单词的行(“ colB == 1&colC == 1”,“ colB == 2&选择colC == 2“,” colB == 1&colC == 2“,” colB == 2&colC == 1“)。我怀疑这将涉及AND和OR条件的组合使用,但是我不确定如何做到这一点。
colA colB colC
become 2 1
become 2 1
become 2 1
borrow 1 2
break 1 2
break 1 1
bridge 1 1
build 1 2
buy 1 2
buy 2 2
buy 2 1
buy 1 1
buy 1 1
因此,在以上示例中,仅选择了“购买”行。输出应该是这样的:
colA colB colC
buy 1 2
buy 2 2
buy 2 1
buy 1 1
buy 1 1
答案 0 :(得分:0)
按'colA'分组后,通过检查filter
(all
)中的元素vector
是否c('11', ...., '21')
{ {1}}选择了“ colB”,“ colC”
%in%
paste