我想知道在记录的每个出生日期出生的独特水坝的数量。我的数据框类似于这个:
dam <- c("2A11","2A11","2A12","2A12","2A12","4D23","4D23","1X23")
bdate <- c("2009-10-01","2009-10-01","2009-10-01","2009-10-01",
"2009-10-01","2009-10-03","2009-10-03","2009-10-03")
mydf <- data.frame(dam,bdate)
mydf
# dam bdate
# 1 2A11 2009-10-01
# 2 2A11 2009-10-01
# 3 2A12 2009-10-01
# 4 2A12 2009-10-01
# 5 2A12 2009-10-01
# 6 4D23 2009-10-03
# 7 4D23 2009-10-03
# 8 1X23 2009-10-03
我用过aggregate(dam ~ bdate, data=mydf, FUN=length)
,但它计算了在特定日期分娩的所有水坝
bdate dam
1 2009-10-01 5
2 2009-10-03 3
相反,我需要有这样的东西:
mydf2
bdate dam
1 2009-10-01 2
2 2009-10-03 2
非常感激您的帮忙!