我有一个如下所示的数据框:
ID Team
11 1
22 2
45 4
45 2
79 3
79 4
100 2
123 1
167 3
167 1
我必须仅对那些ARE重复的行进行子集,直到到达数据帧的末尾。怎么办呢?
答案 0 :(得分:2)
如果您打算对具有重复ID
s
dat <- structure(list(ID = c(11L, 22L, 45L, 45L, 79L, 79L, 100L, 123L,
167L, 167L), Team = c(1L, 2L, 4L, 2L, 3L, 4L, 2L, 1L, 3L, 1L)), .Names = c("ID",
"Team"), class = "data.frame", row.names = c(NA, -10L))
dat[duplicated(dat$ID)|duplicated(dat$ID,fromLast=T),]
# ID Team
# 3 45 4
# 4 45 2
# 5 79 3
# 6 79 4
# 9 167 3
# 10 167 1