标签云

微信群

扫码加入我们

WeChat QR Code

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秒