是否有可能以ret
更易读的方式获得与聚合或 ddply 相同的结果?
time<-c("2013-08-05 15:44:19","2013-08-05 15:44:24","2013-08-05 15:45:19","2013-08-05 15:45:28")
df<-data.frame(time=as.POSIXct(time),col2=c(1,2,2,2),col3=LETTERS[1:4])
mm<-split(df,df[,"col2"])
ret<-lapply(mm, function(x){
mt<-max(x[,"time"])
idx<-x[,"time"]==mt
x[idx,]
}
)
do.call("rbind",ret)