matrix - Apply a function to all column pairs of two matrices in R -
i have 2 matrices same columns , rows names:
> 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
i want compute correlation coefficient between pair of columns between 2 matrices , generate object correlation values every column pairs.
for example, correlation coefficient between first column be:
> cor(metilacion[,1],expresion[,1]) [1] -0.09351992
so, want generate object contains correlation values.
thanks!
you can cor
cor(metilacion,expression) # a2bp1 a2m a2ml1 a4galt aaas #a2bp1 -0.4887051 0.03682951 -0.0404260 0.5795882 -0.03534625 #a2m -0.5909642 0.01572799 -0.1469085 0.3503903 -0.19412101 #a2ml1 0.8006633 0.17242226 0.1294179 -0.5827062 -0.05502329 #a4galt -0.8036390 0.18066923 -0.2026173 0.6824085 -0.32097886 #aaas 0.9033514 -0.54378874 0.7694163 -0.7995712 0.13676285
if need cor
of corresponding columns
diag(cor(metilacion,expresion))
or
mapply(cor, as.data.frame(metilacion), as.data.frame(expresion)) # a2bp1 a2m a2ml1 a4galt aaas #-0.48870510 0.01572799 0.12941787 0.68240850 0.13676285
Comments
Post a Comment