I understand you to want correlations of corresponding rows (** not ccf, which returns a vector ccf for each pair of rows). If that is so,
1) ... in theory, diag(cor(t(A), t(B)) would work without apply, except 196,000 rows is probably too large, and it is probably too inefficient to compute and then throw away all the off-diagonals anyway. 2. ##Use a 3d array. ar <- array(c(A,B),dim=c(dim(A),2)) ## this can also be done by abind() in the abind package apply(ar,1,function(x)cor(x[,1],x[,2])) ## Value is a vector 3. ## probably simplest and best sapply(seq_along(nrow(a)),function(i)cor(a[i,],b[i,])) ## Note: value is a vector, not an array Bert Gunter Genentech Nonclinical Statistics -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Andric Sent: Tuesday, May 22, 2007 8:35 AM To: [email protected] Subject: [R] R-help with apply and ccf Dear R gurus, I would like to use the ccf function on two matrices that are each 196000 x 12. Ideally, I want to be able to go row by row for the two matrices using apply for the ccf function and get one 196000 X 1 array output. The apply function though wants only one array, no? Basically, is there a way to use apply when there are two arrays in order to do something like correlation on a row by row basis? Thanks for your help Michael [[alternative HTML version deleted]] ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
