[R] apply incompatible dimensions error

2007-07-24 Thread Bernzweig, Bruce \(Consultant\)
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=)))

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Gabor Grothendieck
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

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Benilton Carvalho
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)

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Bernzweig, Bruce \(Consultant\)
-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

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Gabor Grothendieck
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

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Benilton Carvalho
, 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

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Bernzweig, Bruce \(Consultant\)
-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

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Bernzweig, Bruce \(Consultant\)
- 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