Next: Profiling in R
Last modified 12/28/07
- To calculate a sum of squares, sum(x^2)
or sum(x*x) is much faster than t(x)%*%x.
- rowSums() and colSums() are fast ways to sum over rows or columns.
- Try to use the standard arithmetic operations, +,-,*,/ whenever
possible to do matrix-vector operations. For example, if D is a diagonal
matrix, then can be done in R as C/diagD where
diagD is a vector of the diagonal elements of D. This is
much faster than doing matrix multiplication using %*%.