【发布时间】:2016-07-03 11:53:15
【问题描述】:
当b 是每个a 的唯一值时,我尝试仅提取行。
这是一些示例数据
a <- c(1,1,2,2,3,3,4,4,5,5,5,6,6,7,7,8,8,9,9,9,9,9,10,10,10)
b <- c(1,2,1,1,5,5,6,1,1,1,3,2,2,1,1,2,3,1,2,3,4,4,1,2,2)
df1 <- data.frame(a, b)
并使用dplyr 包
library(dplyr)
Unique <- df1 %>%
group_by(a) %>%
filter(n_distinct(b))
所需的输出应该是长度为 18 的数据帧
【问题讨论】:
-
是否必须与 dplyr 一起使用?
unique(df1)已经做到了,而且速度更快