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="")))
mat2 <- matrix(sample(501:1000,50), ncol = 5,
dimnames=list(paste("row", 1:10, sep=""),
paste("col", 1:5, sep="")))
f <- function(x,y) cor(x,y)
When the matrices are squares (# rows = # columns) I have no problems.
However, when they are not (as in the example above with 5 columns and
10 rows), I get the following error:
> apply(mat1, 1, f, y=mat2)
Error in cor(x, y, na.method, method == "kendall") :
incompatible dimensions
Any help would be appreciated. Thanks!
- Bruce
**********************************************************************
Please be aware that, notwithstanding the fact that the pers...{{dropped}}
______________________________________________
[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.