Calculate correlation coefficients using common rows of the two matrices

corByRownames(mat1, mat2, ...)

Arguments

mat1

A numeric matrix

mat2

Another numeric matrix

...

Passed cor At least two rows of both matrices must share the same names, otherwise the function will report an error.

Value

A matrix of the dimension \(m \times n\), where m and n are number of columns in mat1 and mat2, respectively. The matrix has an attribute, commonRownames, giving the common rownames shared by the two matrices.

Examples

myMat1 <- matrix(rnorm(24), nrow=6, byrow=TRUE,
  dimnames=list(sprintf("R%d", 1:6), sprintf("C%d", 1:4)))
myMat2 <- matrix(rnorm(35), nrow=7, byrow=TRUE,
  dimnames=list(sprintf("R%d", 7:1), sprintf("C%d", 1:5)))
corByRownames(myMat1, myMat2)
#>            C1           C2         C3         C4          C5
#> C1 -0.3121047 -0.666503364  0.4158111  0.1133333 -0.39083053
#> C2 -0.4122894  0.088724404  0.5347137  0.1220808  0.47403180
#> C3 -0.6937419 -0.200372221 -0.0902017  0.8089499  0.10073400
#> C4  0.5978218 -0.009547803  0.4339425 -0.7000653  0.05422141
#> attr(,"commonRownames")
#> [1] "R1" "R2" "R3" "R4" "R5" "R6"