【发布时间】:2018-06-03 14:46:14
【问题描述】:
df <- data.frame(loc.id = rep(1:2,each = 10), threshold = rep(1:10,times = 2))
当threshold >= 2 和threshold 对于每个loc.id >= 4 时,我想过滤掉第一行。我这样做了:
df %>% group_by(loc.id) %>% dplyr::filter(row_number() == which.max(threshold >= 2),row_number() == which.max(threshold >= 4))
我希望有这样的数据框:
loc.id threshold
1 2
1 4
2 2
2 4
但它返回给我一个空数据框
【问题讨论】:
-
你的问题不清楚
-
我认为您可能需要将条件更改为
>=以获得预期的输出?