关联每一行的矩阵子集

Correlate subset of matrix for each row

我有一个 571x146 矩阵,其中前 73 列是组织样本,最后 73 列是血清样本。

mat<- cbind(Serum, Tissue)
dim(mat)
[1] 571 146

我想将每一行的组织与血清相关联。 F.ex:hsa-let-7a-3p 组织和血清之间是否相关? 我试过类似的东西 cor(mat[1:73,],mat[74:146,])

我的数据:

> head(cbind(dataSerum, dataTissue))
              dataSerum.020 dataSerum.045 dataSerum.080 dataSerum.082 dataSerum.084 dataSerum.086
hsa-let-7a-3p      1.827012      0.110439      0.110439      0.110439      1.390775      0.110439
hsa-let-7a-5p      6.388411      5.103586      5.770176      5.792750      5.972349      5.881312
hsa-let-7b-3p      3.873426      3.902616      4.490432      4.647333      1.390775      4.184897
hsa-let-7b-5p     12.370329     10.901773     10.915286     12.382839     12.572196     11.848387
hsa-let-7c-3p      1.210255      0.110439      0.110439      2.096596      0.110439      2.487538
hsa-let-7c-5p     10.049913      7.609876      9.665469     11.533866      9.250011     10.663856
              dataSerum.088 dataSerum.090 dataSerum.091 dataSerum.092 dataSerum.094 dataSerum.096
hsa-let-7a-3p      1.045003     0.8328381      0.110439      1.541329      1.803120     0.7832888
hsa-let-7a-5p      5.405984     4.5989203      5.410935      5.759703      5.757653     6.5948772
hsa-let-7b-3p      4.888021     5.4085653      4.733195      4.835196      4.786157     4.8730873
hsa-let-7b-5p     11.596264    12.0985457     11.662581     12.340592     11.963892    12.0522698
hsa-let-7c-3p      1.607477     3.3506015      2.093981      3.355425      2.560697     3.2355687
hsa-let-7c-5p     10.334117    10.7623076     10.507376     10.571546     10.675238    11.3099458
              dataSerum.1018 dataSerum.102 dataSerum.1065 dataSerum.1068 dataSerum.1104 dataSerum.112
hsa-let-7a-3p       1.927784     0.8064708       0.110439       0.110439       0.110439     0.8623332
hsa-let-7a-5p       7.455236     6.9096248       6.538260       6.391226       7.820210     5.5041348
hsa-let-7b-3p       4.956808     5.4786059       2.673402       4.141673       3.782756     4.2327853
hsa-let-7b-5p      12.069663    13.7881303      10.314042      11.041668      11.789472    12.0639669
hsa-let-7c-3p       3.878263     2.8286109       0.110439       2.806924       2.807076     2.2544893
hsa-let-7c-5p      10.900419    11.7296762       9.085929      10.652565      11.116274    10.7214136
              dataSerum.113 dataSerum.1167 dataSerum.1196 dataSerum.120 dataSerum.121 dataSerum.1222
hsa-let-7a-3p      0.110439       0.110439       1.016824      0.110439      0.110439      0.7147811
hsa-let-7a-5p      3.525329       5.885213       6.562639      6.497192      5.104070      5.8671717
hsa-let-7b-3p      4.064483       4.094796       3.109492      5.450326      4.560047      3.1607658
hsa-let-7b-5p     10.574141      11.022367       9.892765     13.389285     11.523770     10.6671229
hsa-let-7c-3p      1.882913       1.623137       1.967636      2.019593      1.918653      0.7147811
hsa-let-7c-5p      9.572694       9.382352       9.164980     10.917317     10.046068      9.4001415
              dataSerum.1237 dataSerum.1241 dataSerum.1302 dataSerum.1304 dataSerum.1322 dataSerum.134
hsa-let-7a-3p       1.506357       2.419648       0.110439       1.621290       1.403195      0.110439
hsa-let-7a-5p       5.393388       6.914843       5.337291       7.293159       6.816834      6.834410
hsa-let-7b-3p       3.964471       5.304409       4.494573       4.092131       4.385902      3.025843
hsa-let-7b-5p      11.928062      13.709349      13.123809      10.810837      12.369835     11.027348
hsa-let-7c-3p       2.454954       6.862854       1.520111       4.174212       2.769566      1.588030
hsa-let-7c-5p      11.440675      14.244350      11.429027      11.005578      11.214110      9.793475
              dataSerum.1372 dataSerum.140 dataSerum.145 dataSerum.146 dataSerum.1474 dataSerum.1532
hsa-let-7a-3p       2.248333      0.110439      1.137650      0.110439       0.110439      0.8874652
hsa-let-7a-5p       6.069779      7.082982      5.918264      4.443168       6.379304      5.4154658
hsa-let-7b-3p       3.596326      0.110439      4.685616      3.970195       4.925008      1.7615642
hsa-let-7b-5p      11.739572     15.008134     12.020769     12.109172      13.379541     10.9977873
hsa-let-7c-3p       2.248333      0.110439      3.860720      0.110439       2.897052      0.1104390
hsa-let-7c-5p      10.691202     12.464042     11.080209     10.424234      11.365599      6.5824749
              dataSerum.1540 dataSerum.157 dataSerum.158 dataSerum.1588 dataSerum.1604 dataSerum.161
hsa-let-7a-3p       0.110439      0.110439      1.249884       0.110439       0.110439      1.128105
hsa-let-7a-5p       6.010133      9.116192      6.180033       6.843576       6.395213      6.528847
hsa-let-7b-3p       5.155662      0.110439      5.140688       3.973324       4.673418      4.536223
hsa-let-7b-5p      12.937935     14.652602     13.542906      12.467886      13.302835     13.297839
hsa-let-7c-3p       1.985530      0.110439      3.283527       4.115377       3.818968      2.307753
hsa-let-7c-5p      11.097657     13.242826     11.179949      11.500487      11.265129     10.665662
              dataSerum.1743 dataSerum.176 dataSerum.1808 dataSerum.1809 dataSerum.185 dataSerum.1859
hsa-let-7a-3p       0.110439     0.7518484       0.110439       0.110439      0.110439       0.110439
hsa-let-7a-5p       6.752350     5.5734279       4.470686       8.721870      6.424903       4.668730
hsa-let-7b-3p       2.331288     4.9680525       3.019786       1.892087      5.166887       4.026939
hsa-let-7b-5p      11.993620    12.7230651      11.126879      10.495360     13.044246      12.101369
hsa-let-7c-3p       1.893316     2.7046700       1.583557       3.166080      3.113450       3.352301
hsa-let-7c-5p       9.547269    10.6375748       8.904429      10.552104     11.885120       9.954244
              dataSerum.186 dataSerum.1894 dataSerum.192 dataSerum.201 dataSerum.204 dataSerum.21
hsa-let-7a-3p     0.9897872       0.110439      0.110439      0.110439      1.107041     0.110439
hsa-let-7a-5p     6.4002375       6.435435      6.573398      4.213697      7.010583     5.442620
hsa-let-7b-3p     4.1204840       2.364433      5.680747      6.368581      5.233113     3.675709
hsa-let-7b-5p    12.5605474      10.449590     12.590626     11.781101     13.096574    11.541836
hsa-let-7c-3p     2.7043339       1.923284      2.396208      3.670106      2.911964     2.937443
hsa-let-7c-5p    10.1309695       8.910892     10.658518      8.715887     11.294080    10.663078
              dataSerum.215 dataSerum.2218 dataSerum.236 dataSerum.27 dataSerum.32 dataSerum.38
hsa-let-7a-3p      1.367154       1.984143      0.110439     1.036778     0.110439     0.110439
hsa-let-7a-5p      5.884640       5.497908      5.981895     7.068833     4.359805     5.681387
hsa-let-7b-3p      4.811500       4.531969      4.407851     6.560710     4.098272     4.155882
hsa-let-7b-5p     12.788788      13.382034     11.820819    14.556863    11.425576    12.167628
hsa-let-7c-3p      3.469877       2.772519      2.149753     3.557347     1.999072     3.240711
hsa-let-7c-5p     11.668753      10.885730     10.640346    12.657231    10.038918    10.305388
              dataSerum.39 dataSerum.45 dataSerum.46 dataSerum.bf33 dataSerum.d10 dataSerum.HEP014
hsa-let-7a-3p     0.110439     0.110439     1.390222       0.110439      1.600320         1.554067
hsa-let-7a-5p     6.246589     7.469550     5.030470       6.764492      6.442806         5.704423
hsa-let-7b-3p     4.091493     5.713127     3.256790       5.514486      4.615307         3.088664
hsa-let-7b-5p    11.451453    14.110305    10.414319      13.545592     12.341784        10.493874
hsa-let-7c-3p     1.054888     3.799553     1.390222       2.662292      2.003019         2.733397
hsa-let-7c-5p    11.164581    12.820152    10.039568      11.753841     10.257802         9.542429
              dataSerum.HEP015 dataSerum.mm7 dataSerum.s26 dataSerum.TxHEP-014 dataSerum.TxHEP-015
hsa-let-7a-3p         0.110439      1.934380      1.364235            0.110439            1.097384
hsa-let-7a-5p         6.857792      6.063968      6.405833            7.529581            4.785667
hsa-let-7b-3p         4.862038      5.087062      4.508096            2.775177            4.333530
hsa-let-7b-5p        12.842427     12.665837     12.451983           14.765872           11.150984
hsa-let-7c-3p         4.206344      1.934380      4.191423            1.828111            1.677968
hsa-let-7c-5p        11.869507     11.085609     11.364400           11.435894            9.663560
              dataSerum.TxHEP-018 dataSerum.vs29 dataTissue.020 dataTissue.045 dataTissue.080
hsa-let-7a-3p            0.110439       0.110439      1.7567052      2.6453028     -0.2676069
hsa-let-7a-5p            3.975129       5.342454      9.2999513     12.4293875     13.1549479
hsa-let-7b-3p            4.754537       5.255635      2.7147847      4.4939669      5.9767562
hsa-let-7b-5p           10.844480      11.944910      9.9007205     11.1699167     10.7132014
hsa-let-7c-3p            1.141595       3.288085     -0.2676069     -0.2676069     -0.2676069
hsa-let-7c-5p            8.448021      10.570609      3.6204938      6.5401738      8.2833796
              dataTissue.082 dataTissue.084 dataTissue.086 dataTissue.088 dataTissue.090 dataTissue.091
hsa-let-7a-3p      2.0108843       6.435548      3.2763389       6.091136     -0.2676069      3.3419456
hsa-let-7a-5p     11.2097770      10.039184     13.3357256      10.715223     11.7978678     11.6027192
hsa-let-7b-3p      4.8888433       4.366903      4.7763898       4.540911      2.4616147      4.5911558
hsa-let-7b-5p     10.4403035       9.703632     10.8059019       9.771078     10.3194739     10.0271334
hsa-let-7c-3p     -0.2676069       3.068147     -0.2676069       2.267034     -0.2676069     -0.2676069
hsa-let-7c-5p      6.4465833       7.539852      8.0584140       7.899069      7.1882160      6.3211592
              dataTissue.092 dataTissue.094 dataTissue.096 dataTissue.1018 dataTissue.102
hsa-let-7a-3p      2.6694121       1.733408      3.3317401        3.271602      3.7753918
hsa-let-7a-5p     12.4754796      13.879121     12.0000504       12.781419     13.3801960
hsa-let-7b-3p      5.0881718       4.541053      3.8764695        4.841373      4.2634669
hsa-let-7b-5p     10.8224523      11.200332     10.3064886       11.948258     11.5165940
hsa-let-7c-3p     -0.2676069       3.733661     -0.2676069        1.130019     -0.2676069
hsa-let-7c-5p      6.6691897      10.676993      6.4179911        7.838960      9.6507301
              dataTissue.1065 dataTissue.1068 dataTissue.1104 dataTissue.112 dataTissue.113
hsa-let-7a-3p       4.0694371        2.929427       2.5673669      3.3518618     -0.2676069
hsa-let-7a-5p      12.5581599       12.581633      13.3260643     13.0719168     13.1116824
hsa-let-7b-3p       5.0332967        3.848544       4.3361164      3.3518618      2.7357562
hsa-let-7b-5p      11.7931459       11.363223      11.9087692     10.5921477     11.0117770
hsa-let-7c-3p      -0.2676069        1.629080      -0.2676069     -0.2676069     -0.2676069
hsa-let-7c-5p       6.9692979        7.675619       7.4068177      8.1405710      7.4086426
              dataTissue.1167 dataTissue.1196 dataTissue.120 dataTissue.121 dataTissue.1222
hsa-let-7a-3p       3.3729020       2.6904743      2.8271969     -0.2676069       4.6701190
hsa-let-7a-5p      12.1825722      12.4925116     13.8141608     13.2042435      13.0581665
hsa-let-7b-3p       4.1298063       4.4727492      5.4820220      4.3241738       5.0079198
hsa-let-7b-5p      11.3355945      11.3231984     11.1930770     11.2635565      11.3394651
hsa-let-7c-3p      -0.2676069      -0.2676069     -0.2676069     -0.2676069      -0.2676069
hsa-let-7c-5p       7.9296654       6.7658296     10.1162863      7.9683020       7.4365508
              dataTissue.1237 dataTissue.1241 dataTissue.1302 dataTissue.1304 dataTissue.1322
hsa-let-7a-3p       3.6833442        5.518884       3.3895540      -0.2676069       1.6106379
hsa-let-7a-5p      12.5100949       11.448500      13.2445904      11.3017026      12.4341867
hsa-let-7b-3p       5.0523252        7.168288       4.6411831      -0.2676069       4.5274718
hsa-let-7b-5p      11.5872944       11.658868      11.3166405      10.6384606      11.4602458
hsa-let-7c-3p      -0.2676069        3.271758      -0.2676069      -0.2676069      -0.2676069
hsa-let-7c-5p       8.0407704        9.511722       7.2781527       5.7323227       7.2895831
              dataTissue.134 dataTissue.1372 dataTissue.140 dataTissue.145 dataTissue.146
hsa-let-7a-3p      2.7274474      -0.2676069       4.863868      3.2301310     -0.2676069
hsa-let-7a-5p     10.2746018      11.4008815      12.456531     13.4106428     12.6363247
hsa-let-7b-3p      3.3121740       4.8002490       6.062548      5.0213103      3.3690418
hsa-let-7b-5p      9.6809416      10.4251568      11.211113     11.4228193      9.7089834
hsa-let-7c-3p     -0.2676069      -0.2676069       2.831247     -0.2676069     -0.2676069
hsa-let-7c-5p      5.0488092       6.4334799       7.723956      7.4396062      9.0577247
              dataTissue.1474 dataTissue.1532 dataTissue.1540 dataTissue.157 dataTissue.158
hsa-let-7a-3p       3.3606189       2.1628660       4.4733492     -0.2676069      3.3873437
hsa-let-7a-5p      11.1251905      10.8967604      11.6798829     12.7693438     13.5468211
hsa-let-7b-3p       3.9061567       4.7203919       4.4733492      6.2505020      3.9106960
hsa-let-7b-5p      10.7434824      10.4356661      10.9393956     11.1847246     11.6651980
hsa-let-7c-3p      -0.2676069      -0.2676069      -0.2676069      3.0637102     -0.2676069
hsa-let-7c-5p       6.2547382       6.4046222       7.1921165      9.7085955      7.7396030
              dataTissue.1588 dataTissue.1604 dataTissue.161 dataTissue.1743 dataTissue.176
hsa-let-7a-3p      -0.2676069      -0.2676069      2.3294163      -0.2676069       2.110810
hsa-let-7a-5p      12.0024146      12.3984584     14.0844677      10.3267388      12.355563
hsa-let-7b-3p       3.0871306      -0.2676069      3.7220134       3.4598655       3.497820
hsa-let-7b-5p      10.8097599      10.9837909     11.7047160      10.8176025      10.893408
hsa-let-7c-3p      -0.2676069      -0.2676069     -0.2676069      -0.2676069       2.110810
hsa-let-7c-5p       8.5857063      -0.2676069      7.9652095       4.9703261       5.910196
              dataTissue.1808 dataTissue.1809 dataTissue.185 dataTissue.1859 dataTissue.186
hsa-let-7a-3p       3.2499446       3.2432891      3.4288844      -0.2676069       5.431123
hsa-let-7a-5p      11.2809993      10.1860031     14.6948685      11.7277097      12.938080
hsa-let-7b-3p       4.7483797       3.7854366      3.9762681       5.5167342       6.119754
hsa-let-7b-5p      10.3162832      10.2640922     11.7265303      10.4387134      10.927563
hsa-let-7c-3p      -0.2676069      -0.2676069     -0.2676069      -0.2676069       2.202036
hsa-let-7c-5p       8.3117275       5.1451041      8.7732003       6.9406787       8.009266
              dataTissue.1894 dataTissue.192 dataTissue.201 dataTissue.204 dataTissue.21 dataTissue.215
hsa-let-7a-3p       4.7367247      3.8036792       6.033632      3.3159996     3.5395103      3.0706111
hsa-let-7a-5p      12.0663794     12.6435876      11.903116     13.4080499    13.4425130     15.2359617
hsa-let-7b-3p       6.9233605      4.9472236       4.063503      4.7709745     7.0267594      3.3025483
hsa-let-7b-5p      10.6146572     11.0745632      10.712682     11.2379656    10.6330040     12.5307411
hsa-let-7c-3p      -0.2676069     -0.2676069       2.768195     -0.2676069    -0.2676069     -0.2676069
hsa-let-7c-5p       7.0222378      6.4452256       7.846728      7.6227037    10.4668468      8.9182732
              dataTissue.2218 dataTissue.236 dataTissue.27 dataTissue.32 dataTissue.38 dataTissue.39
hsa-let-7a-3p      -0.2676069      4.8733345     2.4910027     3.6195881      4.638050      4.568997
hsa-let-7a-5p      12.0053100     14.7694293    13.5067711    13.1040470     12.645170     12.527716
hsa-let-7b-3p       4.1506313      3.8450050     4.7215168     3.6195881      5.613782      5.268916
hsa-let-7b-5p      10.5688150     12.0798734    11.8655067    11.1479128     10.850275     11.208723
hsa-let-7c-3p      -0.2676069      0.1516294     0.7041588    -0.2676069      1.809422      2.284747
hsa-let-7c-5p       5.9751726      8.0282855     8.6556157     7.7076017      7.100358      7.950691
              dataTissue.45 dataTissue.46 dataTissue.bf33 dataTissue.d10 dataTissue.HEP014
hsa-let-7a-3p      2.786215      5.225742       4.7253524     -0.2676069         1.4870588
hsa-let-7a-5p     13.045736     11.549679      12.5774745     12.3351727        12.5217899
hsa-let-7b-3p      4.649651      5.035975       5.0065981      5.6767378         4.6147316
hsa-let-7b-5p     11.758369     10.255167      11.1110896     10.1566674        10.9960074
hsa-let-7c-3p      1.512575      1.965484       0.8316063     -0.2676069        -0.2676069
hsa-let-7c-5p      7.553908      7.797788       6.7557454      8.0726127         7.2731762
              dataTissue.HEP015 dataTissue.mm7 dataTissue.s26 dataTissue.TxHEP-014 dataTissue.TxHEP-015
hsa-let-7a-3p         2.6914009     -0.2676069       4.468396            4.8755649            0.9990819
hsa-let-7a-5p        12.6855249     11.0076215      11.528407           13.8836902           11.5087361
hsa-let-7b-3p         4.7995272      5.1775916       6.276755            3.1668239            3.7738952
hsa-let-7b-5p        11.2428324     10.6994018      10.409583           11.1436701           10.6852629
hsa-let-7c-3p        -0.2676069     -0.2676069       2.348228           -0.2676069           -0.2676069
hsa-let-7c-5p         7.2448875      7.2225283       7.288798           10.1153400            7.5524056
              dataTissue.TxHEP-018 dataTissue.vs29
hsa-let-7a-3p           -0.2676069       3.2540185
hsa-let-7a-5p           13.0859296      10.1789061
hsa-let-7b-3p           -0.2676069       5.3227730
hsa-let-7b-5p           10.5197023       9.6318954
hsa-let-7c-3p           -0.2676069      -0.2676069
hsa-let-7c-5p            6.7856285       7.0386244

期望的输出:

variable       correlation
hsa-let-7a-3p  0.74
hsa-let-7b-3p  0.91

您可以使用 apply:

m <- matrix(runif(571 * 146), 571, 146)
apply(m, 1, function(mRow) cor(mRow[1:73], mRow[74:146])

这会产生一个 length 571 的向量,其中包含所有相关性。