如何排除数据框中少于2行的组合?

时间:2015-11-24 16:50:47

标签: r dataframe data.table dplyr

我有这样的df:

ID <- c("ID444","ID465","ID465","ID465","ID465","ID465","ID465")
Measurement <- c("Length","Width","Width","Length","Width","Length","Length")
PASSFAIL <- c("PASS","PASS","PASS","FAIL","FAIL","PASS","PASS")
df <- data.frame(ID,Measurement,PASSFAIL)

然后我做了一个总结,看看有多少组合用于测量和传递失败。

unique <- summaryBy(Measurement~Measurement+PASSFAIL,data=df, FUN = function(x) {c(n=length(x))})
unique

      Measurement PASSFAIL Measurement.n
    1      Length     FAIL             1
    2      Length     PASS             3
    3       Width     FAIL             1
    4       Width     PASS             2

我想删除任何小于2或等于1的组合。我不知道该怎么做。我知道这是一个非常简单的逻辑,但却无法做到正确。有人可以帮助我吗?

我的所需的输出

     ID Measurement PASSFAIL
1 ID444      Length     PASS
2 ID465       Width     PASS
3 ID465       Width     PASS
4 ID465      Length     PASS
5 ID465      Length     PASS

0 个答案:

没有答案