DT[, .SD[which.max(marker),], by=.(id, datep)]

is what I would do.



On Wed Oct 22 2014 at 1:19:17 PM Frank S. <[email protected]> wrote:

> Dear all,
> I'm working with a large database in wich I have some rows which have
> identical id and datep variables. Of these
> duplicated rows, I only want to keep those row associated to the maximum
> value in marker variable. As an example:
> DT <- data.table(
>  id = rep(c(2,5),c(3,2)),
>  datep = as.Date(c('1995-04-20','1995-04-20',
> '1997-02-19', '1998-01-15','1998-01-15')),
>  marker = c(2,8,5,7,5),
>  group=rep(c("A","B"),c(3,2))
>  )
> First, I sort by key variables: id, marker
> DT[order(id,marker)]
>
> But afterwards I've tried different things and I'm not able to what I want:
> DT[!duplicated(DT[c('id', 'datep')])]
> DT[ !(duplicated %chin% c('id','datep'))]
> DT[ !(duplicated %in% c('id','datep'))]
> DT[,!(duplicated(DT[c("id","datep")])), by=list(id,datep)]
> unique(DT[c('id','datep')])
> Please, does anyone know how to do it?
>  _______________________________________________
> datatable-help mailing list
> [email protected]
> https://lists.r-forge.r-project.org/cgi-bin/mailman/
> listinfo/datatable-help
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help

Reply via email to