# gene-gene correlation from two different Tissues

I am stuck on how to do correlation for two independent data sets with common row and column names. A and B are datasets that contain as many rows as genes and as many columns as samples. The rows in A and B represent a common set of genes but measured in two different tissues. The columns represent measurements in the same 5 samples in both A and B. I want to do a correlation between the set of genes in A and B. This is to see if the same genes in both tissues are correlated or not. Since the matrix would be big in my actual data, I only want to retain a correlation coefficient higher than 0.5.

Here I simulate the data set.

set.seed(1)
A <- data.frame(rnorm(100),
rnorm(100),
rnorm(100),
rnorm(100),
rnorm(100))
row.names(A) <- paste0("G_", 1:100)
colnames(A) <- paste0("M_", 1:5)

set.seed(42)
B <- data.frame(rnorm(100),
rnorm(100),
rnorm(100),
rnorm(100),
rnorm(100))
row.names(B) <- paste0("G_", 1:100)
colnames(B) <- paste0("I_", 1:5)


Thank you!

You can use mapply(). ta and tb being transposed data frames of your A and B data frames respectively:
> mapply(cor, ta, tb)[mapply(cor, ta, tb) > 0.5]

• It must be something to do with mapply() treating matrices and data frames differently, not sure. t() outputs matrices not data frames so you can do this: tb = as.data.frame(t(B)). – haci Oct 8 '20 at 12:46