With your sample data
DG <- read.csv(text="day,City,age
4-10,Miami,30
4-10,Miami,23
4-11,New York,24
4-12,San Francisco,30")
you could use dplyr
library(dplyr)
DG %>% group_by(day,City) %>% filter(n()>1)
or base R
DG[ave(rep(1, nrow(DG)), DG$day, DG$City, FUN=length)>1,]
both return
day City age
1 4-10 Miami 30
2 4-10 Miami 23
Or you could use data.table
(as suggested by @Frank)
library(data.table)
setDT(DG)[,if (.N>1) .SD, by=.(City,day)]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…