0

I keep failing at converting code from dplyr to data.table because of the min() function

df.2 <- df.1 %>% group_by(var1) %>% filter(min(var2, na.rm = TRUE) == var2)

Any thoughts and help are greatly appreciated.

Grillo
  • 75
  • 6
  • 1
    `df.2 <- df.1[ , .SD[min(var2, na.rm = TRUE) == var2], by = var1]` – Gregor Thomas Aug 19 '22 at 03:55
  • 1
    An important thing to remember with data.table is that if you filter rows in the first argument of `[` it happens before any grouping. So if you need group logic for the filter, you need to use `.SD` or similar. – Gregor Thomas Aug 19 '22 at 03:59

0 Answers0