Why does mutate() by group take forever?

aggregate, data.table, r

Solution

You don't need `mutate`, just use `start := min(Date)`. I believe that should speed it up a lot.

agg <- mydata[, start := min(Date), by = ID]

Problem

I have a 2.5M x 13 matrix which I try to aggregate by an ID variable. At first I tried with using ddply, but my memory exploded. Afterwards I tried using data.table, which works a lot faster: ``` data <- as.data.table(data) key(data) <- "ID" agg<-mydata[,mutate(.SD, start = min(Date)) , by = ID] ``` Now there's no memory problem, though, so far it takes more than ~4 hours to run this on an Intel i5 2.50GHz with 4.0GB of RAM. Operating system is windows 7, so no parallel computing. What am I doing wrong?

Original source