您好,我正在寻找“min datetime by group”的等价物plyr
(或任何其他包,但 data.table 导致bug #2531的原因)
set.seed(1)
datetimes=c(rep(as.POSIXct("2011-01-01 08:00:00"),3) , rep(as.POSIXct("2011-01-03 08:00:00"),3)) + rnorm(6)
groups=c(rep('a',3),rep('b',3))
X = data.frame(datetime=datetimes,group=groups)
X
# datetime group
#2011-01-01 07:59:59.373546 a
#2011-01-01 08:00:00.183643 a
#2011-01-01 07:59:59.164371 a
#2011-01-03 08:00:01.595280 b
#2011-01-03 08:00:00.329507 b
#2011-01-03 07:59:59.179531 b
预期答案
datetime group
2011-01-01 07:59:59.164371 a
2011-01-03 07:59:59.179531 b