All,

Is there some data.table-idiomatic way to filter based on a previous
observation/row? For example, I want to remove a row if
DT$a[row]==DT$a[row-1].

It could be done by first calculating the lag and then filtering based
on that, but I wonder if there's a more direct way.

The following example works, but my feeling is there should be a more
elegant solution:

( DT <- data.table(a = c(1, 2, 2, 3), b = 8:5) )
DT[, L.a := c(NA, head(a, -1))][a != L.a | is.na(L.a)][, L.a := NULL][]

Thanks,
M
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help

Reply via email to