Efficiently computing a linear combination of data.table columns

后端 未结 2 379
-上瘾入骨i
-上瘾入骨i 2020-11-30 09:38

I have nc columns in a data.table, and nc scalars in a vector. I want to take a linear combination of the columns, but I don\'t know ahead of time

2条回答
  •  执笔经年
    2020-11-30 10:12

    Add this option to your benchmark call:

    ops = as.matrix(DT) %*% cf
    

    On my device it was 30% faster than the matrix multiplication you tried.

提交回复
热议问题