【发布时间】:2015-06-20 17:43:47
【问题描述】:
我有两个具有相同列名和行名的矩阵:
> metilacion[1:5,1:5]
A2BP1 A2M A2ML1 A4GALT AAAS
paciente1 0.2804884 0.5816559 1.1814702 -0.6234276 -0.3997400
paciente2 0.5122471 1.2944264 0.5673766 0.4490407 -0.6045510
paciente3 -0.3116356 1.6085049 0.9970350 0.3379215 -0.4787046
paciente4 -0.7220941 0.8771948 2.1445474 -0.5837802 -0.4848246
paciente5 -0.3369999 1.5885716 0.8185654 0.2374583 -0.5698858
> expresion[1:5,1:5]
A2BP1 A2M A2ML1 A4GALT AAAS
paciente1 -0.9082274 -0.17736185 0.8846485 -0.36059775 -0.5624139
paciente2 -1.7152290 1.62368019 0.3292617 1.35968899 -0.9220157
paciente3 -1.0581859 0.33028098 1.1020073 0.01870851 -0.9669236
paciente4 -0.8389615 1.33754885 0.5122861 -0.14583960 -0.8196533
paciente5 -1.5273835 0.06418637 0.2695209 0.03381359 -0.4461490
我想计算两个矩阵之间所有列对之间的相关系数,并为每个列对生成另一个具有相关值的对象。
例如,第一列之间的相关系数为:
> cor(metilacion[,1],expresion[,1])
[1] -0.09351992
所以,我想生成一个包含所有相关值的对象。
谢谢!
【问题讨论】:
-
试试
cor(metilacion,expresion)根据?cor,"If ‘x’ and ‘y’ are matrices then the covariances (or correlations) between the columns of ‘x’ and the columns of ‘y’ are computed. -
如果你只是寻找对应的列,那么
diag(cor(metilacion,expresion))