[R] rank correlation and distance between two different matrices
Jari Oksanen
jarioksa at sun3.oulu.fi
Mon May 12 09:44:48 CEST 2003
On Mon, 2003-05-12 at 01:36, Luca De Benedictis wrote:
> Dear all,
> in package Hmisc `rcorr' computes a matrix of Spearman's `rho' rank
> correlation coefficients for all possible pairs of columns of a matrix.
> What if I want a matrix of rank correlation coefficients for pair of
> columns of two different matrices?
>
> I have the same question about distance metrics in package Vegan. The
> function 'vegdist' computes distance indexes for all possible pairs of
> row of a matrix. What if I am interested in comparing each single row of
> matrix A with the correspondent row of matrix B?
Wasteful, but may do what you asked for:
> A <- matrix(runif(120), nrow=10, ncol=12)
> B <- matrix(runif(120), nrow=10, ncol=12)
> diag(as.matrix(dist(rbind(A,B)))[11:20, 1:10])
[1] 1.362722 1.381713 1.526918 1.565419 1.103431 1.384486 1.186895
[8] 1.512283 1.401761 1.817098
cheers, jari oksanen
--
Jari Oksanen <jarioksa at sun3.oulu.fi>
More information about the R-help
mailing list