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 &lt;- data.frame(rnorm(100), 
                rnorm(100),
                rnorm(100), 
                rnorm(100),
                rnorm(100))
row.names(A) &lt;- paste0(&quot;G_&quot;, 1:100)
colnames(A) &lt;- paste0(&quot;M_&quot;, 1:5)

set.seed(42)  
B &lt;- data.frame(rnorm(100), 
                rnorm(100),
                rnorm(100), 
                rnorm(100),
                rnorm(100))
row.names(B) &lt;- paste0(&quot;G_&quot;, 1:100)
colnames(B) &lt;- paste0(&quot;I_&quot;, 1:5)

Thank you!
You can use mapply(). ta and tb being transposed data frames of your A and B data frames respectively:
&gt; mapply(cor, ta, tb)[mapply(cor, ta, tb) &gt; 0.5]

      G_3       G_5       G_9      G_10      G_11      G_15      G_20      G_23      G_25      G_26      G_33      G_40      G_43      G_48      G_57      G_60 
0.5346591 0.8066507 0.8379777 0.6752681 0.7221359 0.5285787 0.7333045 0.5627962 0.6533379 0.7256878 0.5996492 0.6486557 0.5108215 0.7386332 0.6596823 0.6919915 
     G_63      G_72      G_76      G_80      G_81      G_90      G_97      G_98      G_99 
0.5589583 0.8391917 0.7608801 0.8003665 0.6364557 0.5030968 0.7298439 0.5693024 0.5709411