Hi,
I've created the following two matrices (mat1 and mat2) and a function
(f) to calculate the correlations between the two on a row by row basis.
mat1 - matrix(sample(1:500,50), ncol = 5,
dimnames=list(paste(row, 1:10, sep=),
paste(col, 1:5, sep=)))
Your apply is trying to take the correlations of the rows of mat1 with the
columns of mat2 which, of course, does not work if they have different
numbers of columns. I think you mean to take the correlations of the columns
of mat1 with the columns of mat2. For example, to take the correlations
of
are you positive that your function is doing what you expect it to do?
it looks like you want something like:
sapply(1:10, function(i) cor(mat1[i,], mat2[i,]))
b
On Jul 24, 2007, at 11:05 AM, Bernzweig, Bruce ((Consultant)) wrote:
Hi,
I've created the following two matrices (mat1 and mat2)
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 24, 2007 11:31 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] apply incompatible dimensions error
Your apply is trying to take the correlations of the rows of mat1
PROTECTED]
Sent: Tuesday, July 24, 2007 11:31 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] apply incompatible dimensions error
Your apply is trying to take the correlations of the rows of mat1 with
the
columns of mat2 which, of course, does not work
, Bruce (Consultant)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] apply incompatible dimensions error
are you positive that your function is doing what you expect it to do?
it looks like you want something like:
sapply(1:10, function(i) cor(mat1[i,], mat2[i,]))
b
On Jul 24, 2007, at 11:05
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 24, 2007 11:43 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] apply incompatible dimensions error
Then try this:
cor(t(mat1), t(mat2))
Also note
1. the above
- Bruce
-Original Message-
From: Benilton Carvalho [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 24, 2007 11:31 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] apply incompatible dimensions error
are you positive that your function is doing what you