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 wayrcorr(DT[subgroup][, !'Group', with=F])# Faster wayrcorr(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?

I think this answer should be of some help, in addition to Richard's nice answer.

**2019年04月18日31分46秒**

Absolutely! That was an extremely helpful answer, thanks!

**2019年04月19日31分46秒**

Thanks! I figured something like that was going on.

**2019年04月19日31分46秒**

Chris, it works on the same premise that [ would in base R, if that helps

**2019年04月18日31分46秒**

- dplyr on data.table, am I really using data.table?
- data.table vs dplyr: can one do something well the other can't or does poorly?
- R - slow performance in creating lots of data.table objects
- R: Calculate differences between rows in data.table
- How to speed up subset by groups
- Convert huge sparse matrix into data.table for faster subsetting in R
- In R's data.table, how is the key of a data.table preserved into subsets referenced using .SD?
- data.table: Merging nearby genomic features
- Data.table - subsetting within groups during group by is slow
- Inequality Subsetting in data.table - Binary Searching
- Subset a data.table to get the most recent 3 or more rows within a duration by group

ADS