Dear all, I want to compute pairwise correlations between all rows of two matrices where the pairs are formed by taking all rows from each matrix with a common factor. In other words, I want to take all pairwise correlations between rows after stratifying by a factor (the same factor) in each matrix. More concretely, I have factor for matrix 1 like: A A B B C E G And for matrix 2, A B C D E F G And two matrices with the same number of columns. I want to get correlations between row 1 of matrix 1 and row 1 of matrix 2, row 2 of matrix 2 and row 1 of matrix 2, etc. I just can't seem to get the correct combination of "apply" functions to do this. Any ideas? Thanks, Sean