I want to add two columns to the mtcars dataset and keeping all the data If I add one column, it's work :
dt <- as.data.table(mtcars)
dt[, max_mpg := max(mpg), by = cyl][]
But when I add the second columns I have an error :
dt[, list(max_mpg := max(mpg), min_mpg := min(mpg)), by = cyl][]
I want to keep all others column, something similar to the mutate function in dplyr
Thanks