# Re: [R] R-help with apply and ccf

From: Bert Gunter <gunter.berton_at_gene.com>
Date: Tue, 22 May 2007 09:35:32 -0700

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: r-help-bounces_at_stat.math.ethz.ch
[mailto:r-help-bounces_at_stat.math.ethz.ch] On Behalf Of Michael Andric Sent: Tuesday, May 22, 2007 8:35 AM
To: r-help_at_stat.math.ethz.ch
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?

Michael

[[alternative HTML version deleted]]

R-help_at_stat.math.ethz.ch 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.

R-help_at_stat.math.ethz.ch 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. Received on Tue 22 May 2007 - 16:59:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 May 2007 - 17:31:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.