I recently noticed in some old code that I had been including extra square brackets when subsetting a data.table
and performing a function repeatedly (in my case, calculating correlation matrices). So,
# Slow way
rcorr(DT[subgroup][, !'Group', with=F])
# Faster way
rcorr(DT[subgroup, !'Group', with=F])
(The difference being after subgroup
). Just out of curiosity, why does this occur? With the extra brackets, does data.table
have to perform some extra computations?