I have a 10000 x 7 data.table dat . I would like to multiply each row of dat by a 7x7 matrix c. I have tried the following
apply(dat, 1, function(x) sqrt(as.matrix(x) %*% as.matrix(c) %*% t(as.matrix(x))))
I get this error
Error in as.matrix(x) %*% as.matrix(c) : non-conformable arguments
This function works when I take a single row from dat (so 1 x 7) but not when I use apply.
How do I make this work using apply?
Thanks!
Additional info - I could achieve what I need another way. I could multiply the entire data.frame by the matrix and take sqrt(diag(x))
. However, I need to do this a lot of times, so it would be more efficient to take this row by row and return a single figure.