Thanks Charles, Martin,
Substantial improvement with the vectorized solution. Here is a quick benchmark:
# The loop-based solution:
nestedCos = function (x) {
if (is(x, Matrix) ) {
cos = array(NA, c(ncol(x), ncol(x)))
for (i in 2:ncol(x)) {
Jose Quesada wrote:
Thanks Charles, Martin,
Substantial improvement with the vectorized solution. Here is a quick
benchmark:
# The loop-based solution:
nestedCos = function (x) {
if (is(x, Matrix) ) {
cos = array(NA, c(ncol(x), ncol(x)))
for (i in
(Extremely sorry, disregard previous email as I hit send before pasting the
latest version of the example; this one is smaller too)
Dear R users,
I want to apply a function that takes two vectors as input to all pairs
(combinations (nrow(X), 2))of matrix rows in a matrix.
I know that ideally,
I am rusty on 'Matrix', but I see there are crossprod methods for those
classes.
res - crossprod( x , x )
gives your result up to scale factors of sqrt(res[i,i]*res[j,j]), so
something like
diagnl - Diagonal( ncol(x), sqrt( diag( res ) )
final.res - diagnl %*% res
On Tue, 23 Jan 2007, Charles C. Berry wrote:
I am rusty on 'Matrix', but I see there are crossprod methods for those
classes.
res - crossprod( x , x )
gives your result up to scale factors of sqrt(res[i,i]*res[j,j]), so
something like
diagnl - Diagonal( ncol(x), sqrt( diag(