First, split the df$ID
by Month
and use intersect
to find elements common in each sub-group.
Reduce(intersect, split(df$ID, df$Month))
#[1] 4 6
If you want to subset the corresponding data.frame, do
df[df$ID %in% Reduce(intersect, split(df$ID, df$Month)),]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…