DT[, .SD[which.max(marker),], by=.(id, datep)]<div><br></div><div>is what I would do.<br><br><div><br></div></div><br><div class="gmail_quote">On Wed Oct 22 2014 at 1:19:17 PM Frank S. <<a href="mailto:f_j_rod@hotmail.com">f_j_rod@hotmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


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