I heard (from my frnd) that mathematical operations on data.table is way faster than on matrix. I am trying to compute the dot.product of two matrix of size 30kx30k, and looking for the time taken
matrix1 = matrix(rexp(200, rate=.1), ncol=30000,nrow=30000)
matrix2 = matrix(rexp(200, rate=.1), ncol=30000,nrow=30000)
product = matrix1 %*% matrix2
Same thing I want to do with using data.table
dt1<- as.data.table(matrix1)
dt2<- as.data.table(matrix2)
Can you please tell me if there is easier way to do dot product on data.table(without converting them into matrix)?
The premise in this question is incorrect.
data.table
s, like data.frame
s are lists of vectors.
In contrast, a matrix is a single vector with a dimension attribute.
There is an overhead associated to lists, which can be avoided if your data can fit a matrix.
data.tables
are faster relative to data.frames (and depending on the application, lists themselves), or when using another vector as an index to iterate against.
However, for straight matrix multiplication, stick to matrix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With