【发布时间】:2015-10-22 22:11:47
【问题描述】:
我有如下数据:
ID category class
1 a m
1 a s
1 b s
2 a m
3 b s
4 c s
5 d s
我想通过仅包含具有多个 (> 1) 不同类别的那些“ID”来对数据进行子集化。
我的预期输出:
ID category class
1 a m
1 a s
1 b s
有办法吗?
我试过了
library(dplyr)
df %>%
group_by(ID) %>%
filter(n_distinct(category, class) > 1)
但它给了我一个错误:
# Error: expecting a single value
【问题讨论】: