我正在初始化data.frame,如下所示:
combdat <- data.frame(matrix(nrow=50), check.names=FALSE)
在循环中,我现在想要填写其他列。这是这样的:
combdat[,mkr] <- mkrgeno
其中mkr是某个字符,而mkrgeno是相同大小的矢量。但是mkr的某些值是相同的。我需要保留它们。现在他们只会被覆盖。虽然我设置了check.names = FALSE
有人对我有建议。 感谢
富
好的,谢谢,我会尝试更详细地提出我的问题。
我的列表markerinfo包含有关标记的某些信息:
> markerinfo
marker chr pos lod pheno
1 c1m22 1 213.2983 9.1495699 RAPGEF2
2 c4m14 4 131.0000 8.5438345 CACNA1E
3 c1m8 1 63.0000 9.0002544 CACNB3
4 c3m22 3 228.0000 7.1775450 RASA2
5 c1m31 1 305.0000 6.4748053 CACNG6
6 c3m22 3 230.3826 6.5638616 PRKCG
7 c4m11 4 103.0000 6.3592497 CACNA1B
8 c4m26 4 256.0000 8.5450810 CACNA1F
9 c4m14 4 139.0000 5.3257424 CACNG3
10 c2m1 2 0.0000 7.8765658 CACNA1G
11 c2m2 2 13.0000 10.0825268 PRKCA
12 c2m16 2 159.0000 9.2080541 CACNA1D
13 c4m20 4 191.7279 7.2340899 SOS2
14 c2m3 2 16.0000 5.9131295 CACNG5
15 c3m22 3 230.3826 6.7322605 CACNA1A
16 c3m8 3 75.4555 1.1470464 RASGRF1
17 c3m8 3 70.0000 1.9991043 MRAS
18 c1m30 1 288.2238 1.8443845 RRAS2
19 c4m16 4 157.0000 2.1455832 RASGRP3
20 c3m30 3 320.0000 1.9721441 HRAS
21 c1m10 1 90.0000 1.8833757 RASGRF2
22 c3m16 3 161.6888 2.1163401 NRAS
23 c3m20 3 201.9852 2.6265899 RASGRP1
24 c3m30 3 319.4977 1.3677933 KRAS
25 c3m22 3 230.3826 0.7012214 RASGRP2
另一个data.frame是基因型:
c3m1 c3m2 c3m3 c3m4 c3m5 c3m6 c3m7 c3m8 c3m9 c3m10 c3m11 c3m12 c3m13 c3m14 c3m15 c3m16 c3m17 c3m18 c3m19 c3m20 c3m21 c3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2 2 2 2
V8 1 1 1 1
V9 2 2 2 2
V10 2 2 2 2
V11 2 2 2 2
V12 1 2 2 2
V13 2 2 2 2
V14 2 2 2 2
V15 1 1 1 1
V16 1 1 1 1
V17 1 1 1 1
V18 2 2 2 2
V19 2 1 1 1
V20 1 1 1 1
V21 2 2 2 2
V22 1 1 1 1
V23 2 2 2 2
V24 2 2 2 2
V25 2 2 2 2
V26 1 1 1 1
V27 1 1 1 1
V28 2 2 1 1
V29 1 1 1 1
V30 1 1 2 2
V31 2 2 2 2
V32 1 1 2 2
V33 1 1 2 2
V34 1 1 1 1
V35 1 1 1 1
V36 1 1 1 1
V37 1 1 1 1
V38 1 2 2 2
V39 1 1 1 1
V40 1 1 1 1
V41 2 2 2 2
V42 2 1 1 1
V43 1 1 1 1
V44 1 1 1 1
V45 2 2 2 2
V46 1 1 2 2
V47 2 2 2 2
V48 2 2 2 2
V49 2 2 2 1
V50 2 2 2 2
另一个名称为:phenotype
> phenotype
RAPGEF2 CACNA1E CACNB3 RASA2 CACNG6 PRKCG CACNA1B CACNA1F CACNG3 CACNA1G PRKCA CACNA1D SOS2
1 -0.247595001 0.053503367 -0.236269632 -0.198393959 0.30226149 0.034393665 0.13201747 -0.055123952 -0.4775578 -0.16406024 -0.601510801 -0.74241018 0.003437553
2 0.076554542 -0.296400594 -0.204362787 -0.083725326 -0.51309205 0.008746035 0.49724817 -0.141674911 -1.5563250 -0.28751925 -0.152694444 -0.83115868 -0.520475369
3 -0.327202333 0.001312523 0.013790261 0.074576720 0.23008238 -0.050573176 -1.04673228 -0.330784609 0.5481467 -0.84388147 -0.743829290 -0.55692338 -0.542878574
4 -0.007847655 -0.138671725 -0.149620332 -0.819362934 -0.11386931 -0.041000430 -0.16221890 0.157342905 -0.4304658 -0.04136305 0.140892816 -1.43966569 -0.502489598
5 -0.288891373 -0.453451438 -0.203315372 -0.432877782 -0.32638230 -0.079509208 -1.07767644 -0.239044759 -2.6685509 -0.34506117 -0.601583079 0.06418028 -0.447845591
6 -0.819438873 -0.186128793 0.010946957 -0.541158848 -0.05467246 -0.091256991 -0.14121849 0.120465369 -0.7412188 -1.45824366 -0.742750372 -0.65559390 -0.024424118
7 0.056713692 0.099570795 -0.140081980 -0.249675499 -0.54844575 -0.142449430 -0.17804642 -0.193517791 -2.8180865 -0.37995253 0.521983735 -0.13506427 -0.496292115
8 -0.415822882 -0.234501809 0.045971377 -0.501303875 0.10064320 -0.123989099 -0.18390119 -0.272184476 -2.3932719 -0.17459784 0.041698873 -0.58292029 -0.030478251
9 0.216626060 -0.055785714 0.102465484 -0.296597579 -0.63187464 -0.043925124 -0.73290772 0.086194905 1.2253629 -0.26787759 -0.186213820 0.21540883 -0.409209752
10 -0.172889555 -0.359033332 0.059976873 -0.122362142 -0.57597543 -0.039439871 -0.37358470 0.046816519 -0.2194930 0.44557540 -0.008582745 0.04681091 -0.151858633
11 -0.799370277 -0.390225142 0.092905430 -0.539360659 -0.46040156 -0.080978159 -1.35509517 -0.183647290 -2.0786691 -0.53105091 -0.537946690 0.15503760 -0.250068125
12 0.165948180 0.084380299 0.072471995 -0.257986088 -0.31888913 -0.113180297 0.09108201 0.081261902 0.4084345 -0.32413522 -0.410390899 -0.52705454 -1.311315609
13 -0.151699952 -0.345160750 0.024127039 -0.199062545 -0.35710011 -0.101713530 -1.52298182 -0.131191677 -1.4151031 0.13075608 -0.112750159 -0.09761248 -0.448443675
14 -0.064050378 0.058414370 -0.049131860 -0.438722188 0.46253165 -0.085058699 -0.48949571 0.312177213 -0.4383044 -0.13332403 -0.952470633 -0.10016991 -0.738450721
15 -0.252830650 -0.021360957 -0.054884002 -0.132821999 0.24029851 0.032595174 -0.28201065 -0.134742072 -1.2429264 -0.20965743 -0.266581307 -0.65461311 -0.026886166
16 -0.302939138 -0.237659778 -0.173316135 -0.433111666 -0.49102642 -0.169569976 -0.14919939 -0.024873565 -1.7566415 -0.11697234 0.250150721 -1.00971694 -0.314707578
17 -0.027397752 -0.220213983 -0.020104605 -0.260175395 0.36690904 -0.015439485 -1.64675598 -0.341331701 1.1341947 0.19718194 0.040220128 0.21718090 -1.082049767
18 -0.084826002 0.075130631 0.085664240 -0.516533930 0.05420691 -0.111368755 -0.54866864 -0.246852143 -0.1673859 0.54867571 -0.491091471 -0.64419595 -0.417058365
19 0.076420274 -0.198417039 -0.209613388 0.275960810 0.20461276 -0.016330089 -2.44087703 0.016533904 -0.9745876 -0.32916054 -0.886846124 -0.03904152 0.423648190
20 -0.341758547 0.027599210 -0.238241196 -0.122481806 -0.53322283 -0.041335840 -0.09748360 0.109385536 0.7184183 -0.42004508 -0.297868841 0.02331034 -0.176874436
21 -0.729225854 -0.366947864 -0.151319971 -0.766507590 -0.93109904 -0.120188998 -0.82125694 -0.069669901 -1.8344670 0.19827344 -0.121866097 -0.64905504 -0.309849450
22 -0.375156253 0.023848706 -0.084361744 -0.444354626 -0.66319529 -0.062962171 -1.20604478 0.168518715 -1.5501544 0.47227482 -0.209564431 -0.47454099 -0.057838134
23 -0.254021124 0.169933007 -0.110124957 -0.321290108 -0.25074586 -0.002748504 -1.67191531 -0.213003128 -0.6702960 0.06601284 0.419818706 -0.24339589 -0.900376250
24 -0.115377716 -0.069793465 -0.082424787 -0.207820569 -0.62402649 -0.057047717 -0.28566344 -0.343388680 -0.9703774 -0.05548410 -0.226484770 -0.73331271 -0.699834400
25 -0.049844861 -0.005899354 -0.014298567 -0.058495200 -1.32936915 -0.080242402 0.21312235 -0.469668455 0.3296792 -0.40816963 0.169496411 -0.06951457 0.678321997
26 -0.722770403 0.103085237 -0.107956995 -0.453234395 -0.79713145 -0.010894595 -0.02192121 -0.183129347 -0.4671715 -0.24454782 0.140808502 -0.16672267 -0.297979736
27 0.177156038 -0.352948087 0.126134036 0.009680394 -0.53116648 0.083284652 -2.56881648 0.040743856 -1.3867899 -0.30346968 -0.943847562 -1.27918873 0.074066589
28 0.031014348 -0.096368514 -0.191044463 -0.150761960 -0.34080995 -0.082406406 0.81100676 0.081447585 -0.4011565 0.46952945 -0.126056643 -0.39482906 0.487768932
29 -0.175479066 -0.406803418 0.060241581 -0.630242987 -0.04177606 -0.099102694 -1.77644280 -0.220901308 -1.0807459 0.25538082 -0.127072554 -0.28244767 0.077844220
30 0.067184617 0.135066792 0.061038582 -0.005188869 -0.28276832 0.002666423 1.11312551 -0.261943690 0.9199570 -0.65210434 -0.308977705 -0.74132895 -0.089614346
31 0.077892704 -0.235195609 -0.067162872 -0.207711784 0.02699528 -0.005653163 -1.61297664 -0.338387970 -0.2485027 -0.10887056 0.343968213 0.09719695 -0.452561385
32 0.142403286 -0.026388719 -0.065678040 -0.362428853 -0.19390021 -0.130526170 -1.21100755 -0.350326700 -1.2818116 -0.72894545 -0.654865598 -0.75242740 -0.379810157
33 -0.001080476 -0.290697156 0.011388500 0.139363744 0.27888665 -0.100895638 0.39220173 -0.346996776 -0.7863979 -0.52910994 -0.558958463 0.31595835 -0.710613795
34 0.224116945 -0.185072933 0.086483429 -0.348059767 -0.25522243 -0.126570401 -2.48462353 -0.402525824 -1.8282210 -0.71284302 0.003787240 0.33055507 -0.485361798
35 -0.254131666 -0.181962657 0.134810146 -0.144177046 -0.42946649 0.006665253 -1.31883436 -0.233832760 -0.8644715 0.02096703 -0.386481233 -0.72159749 0.091061479
36 0.078173409 0.069614224 -0.027333201 -0.338889055 -0.08953657 -0.048366331 -1.05945722 -0.005647055 -0.5515289 -0.99689326 -0.499325729 0.25250542 -0.630618039
37 -0.383263187 0.050446587 0.042835279 -0.187032348 0.10888308 -0.044352563 -0.14934550 -0.123438315 1.1205628 -0.59339281 -0.824166347 -0.50010055 0.362946526
38 0.155765532 -0.095113895 -0.028232352 -0.341382444 -0.28993519 -0.063198747 -0.74942280 -0.262175258 0.3796110 -0.64149439 0.038476888 -0.15428205 -0.070443511
39 -0.352871059 -0.154463839 -0.040044333 -0.215973910 -0.70080752 -0.030485881 -1.59167190 -0.018228487 -2.7482696 -0.81423002 -0.990327664 0.02797165 -0.961506882
40 -0.027887194 -0.500539888 0.101565681 0.026081728 -0.37318368 0.030271868 -1.56720146 0.114323657 -0.9604690 -0.83847006 -0.616284751 -0.22106937 -0.817229295
41 -0.116324675 0.141997059 0.011066622 -0.637030608 -0.06816308 -0.139064501 -0.21884155 -0.133162057 0.3200013 0.40302112 0.196245908 -0.44456908 -0.060186732
42 -0.011563437 -0.097908807 0.010180963 -0.356297511 0.25810039 -0.053495480 -1.23448236 -0.075325095 -2.1873328 0.25853977 0.024608949 -0.24320912 -0.865864499
43 -0.473180079 -0.175778274 -0.153653640 -0.492266908 -0.72545341 -0.089492114 -1.52409341 -0.113111386 -1.8098738 -0.23081989 -0.143859625 -0.33247673 -0.930370376
44 -0.301982544 -0.276093471 -0.172829397 -0.165867999 -0.09716023 -0.074000281 -1.29494575 -0.284384336 -0.3640354 -0.98837691 -0.583165895 -0.22244048 -0.389223572
45 -0.035837132 0.089487455 0.043398895 -0.261321417 -0.14740720 0.086069259 0.50424191 -0.435393685 -0.6916679 0.08837666 -0.764933697 -0.15527777 -0.180500006
46 -0.283577759 0.033526022 -0.053893390 -0.276804767 -0.38757922 0.049021497 1.11676571 -0.165603000 -1.4368988 0.08869823 0.165745244 -0.43123024 -0.409150399
47 -0.579455295 0.045838903 -0.174331523 -0.503703045 -0.51013334 -0.018538629 0.24724654 -0.382273065 -0.2014670 -0.67669484 -0.653328789 0.46375442 -0.481676959
48 -0.308546234 -0.047014302 -0.005449878 -0.350135893 -0.16086990 -0.090971861 0.11738860 -0.360362823 -0.3117357 -0.92804263 -0.430577252 0.38097823 -0.426938081
49 -0.165320629 -0.436561117 -0.022108887 -0.412614936 0.20412609 0.003279052 -0.77152209 0.211526672 -0.5851201 -0.18290809 -0.284230585 0.30449400 -0.666071768
50 -0.142082710 0.195017303 -0.121702032 0.077439475 -0.47426071 0.055089372 -0.82942407 -0.249394753 0.5139078 -0.52850805 -0.707774591 0.02486043 -0.529796003
CACNG5 CACNA1A RASGRF1 MRAS RRAS2 RASGRP3 HRAS RASGRF2 NRAS RASGRP1 KRAS RASGRP2
1 -1.08126573 -0.10466468 0.16163511 5.2884330 1.4807031 1.367194844 -5.3632946 8.854311810 -1.590394 5.46299955 3.39043935 -0.6188210
2 -0.20103987 0.02859079 -4.04956365 6.8065804 9.7156082 2.358011759 7.5529682 -1.371397362 5.512496 2.38105873 -4.31024938 -2.9758226
3 -0.56279304 -0.49473575 0.93100155 13.3018509 4.7819748 -0.830227776 7.1269586 1.639458379 5.579675 1.92566166 -10.04349925 -3.9823054
4 -0.17721434 -0.13495743 -4.18967059 7.7963292 2.4795673 0.849823268 16.4843104 1.625120794 2.538493 -1.96693411 -1.06650587 2.9583095
5 -0.21284845 -0.41776136 11.57622331 7.8696230 25.3334550 0.525216862 21.7506102 1.804542827 27.144583 1.33103943 14.91107071 4.3580818
6 0.26966929 -0.57921249 -3.81118227 -1.7711352 2.6537342 2.381451473 0.3413279 0.002745248 11.787951 -2.72785260 5.81449916 1.1492321
7 -0.05721931 -0.61373510 3.20661730 17.0161591 8.3848898 9.128073635 10.0460744 7.427485748 6.423633 8.58609614 5.14330065 0.2455554
8 -0.23483474 -0.30007284 7.44882239 -4.1520715 2.5809601 0.007694412 14.4026853 6.009882772 1.973626 5.85650616 -4.99508071 1.4778224
9 -0.30401185 -0.23601064 0.61950230 2.1421284 15.4745282 -0.515190084 5.7490335 -3.364087292 12.305191 0.68371891 0.70766236 0.7915359
10 0.03069795 0.17789637 5.48077430 0.1797954 1.5320631 -0.612153126 -11.1569228 2.314820314 5.364269 -1.03632032 7.25132489 3.9454336
11 -0.67484374 -0.24910596 2.32388243 17.9765927 0.9794240 10.700691074 7.1050062 4.714036496 15.891228 -4.31287607 7.62253612 5.1733717
12 -0.23985708 -0.38664533 5.49113542 6.9358357 20.5868853 -0.490459011 19.0955840 -0.187311045 -11.228341 -2.01774050 2.46021292 2.9611938
13 -0.17565650 -0.26472802 -3.66145265 12.2382531 18.9846037 -1.676584866 15.2614596 4.241818360 11.685053 -1.41970648 -8.67808713 5.7914843
14 -0.66123979 -0.73403494 -1.47051990 -9.4605317 7.9187982 1.649205050 5.5260746 2.236724615 -5.689584 0.08904104 -7.61932439 -2.3718501
15 -0.25993662 -0.36155808 0.47540397 0.2766627 -12.6713829 3.527719828 16.7505891 -4.031521995 -6.139259 1.16441221 -6.18252342 1.0479288
16 -0.03146197 -0.45563938 7.13155463 -8.8844448 10.2941475 6.470602700 11.8131578 2.036032005 -3.021039 1.27196373 16.98691230 5.9919408
17 0.15062972 -0.14899016 -5.17104361 27.1526356 10.6209803 8.107969651 11.0779712 5.968404297 13.698359 2.93330073 20.28969711 -1.1704762
18 -0.25937867 -0.39833982 -0.43088475 -5.6251327 11.3899990 -0.318345728 3.1713730 0.760007843 5.409240 -3.68088307 -10.11778528 4.8975433
19 -0.87451283 -0.05959917 -2.53664942 29.4869423 19.1536567 -4.591416100 27.3860278 3.156809354 7.025175 4.72109032 26.79484568 2.0115602
20 -0.67964587 0.27642731 -7.18238442 5.0073861 9.8321189 0.380995576 1.9077432 -0.585178489 -3.439573 2.59522601 -8.74681890 -0.6800699
21 -0.49629567 -0.56934938 2.23942230 22.8194269 5.2645346 -2.428571330 6.1776451 2.611162565 18.775754 1.10296129 12.87445853 -4.3216192
22 0.00724720 -0.70303883 -1.43444204 1.8773895 9.1167518 3.582722007 9.7741579 0.028240658 4.460745 2.27952502 14.99544664 -0.9230170
23 -0.10643328 -0.67769320 6.75704004 3.0189378 -0.9081308 2.255448682 9.2941211 2.151332408 -2.619788 1.16186606 -5.75794077 3.8895972
24 0.35597240 0.06858421 -1.72085135 10.4151256 -0.1591937 1.167127427 4.6532448 0.296189520 -10.270647 -0.35558702 16.91723551 -1.0866788
25 0.10449039 0.22289001 6.69617230 6.2155570 10.8483718 -1.374067174 3.7386102 1.255906864 5.792042 6.56478190 5.65215300 4.2867125
26 0.11049705 -0.26850303 -2.60011742 1.7766863 -7.9563835 -1.795606943 2.2133029 -4.103202628 5.503321 -1.80881337 6.71979360 5.2476183
27 -0.43247910 0.06570798 3.12944595 26.3058088 23.7036553 1.572823145 41.4230817 -3.123108372 44.661343 6.00690771 12.20911459 9.3681238
28 -0.06832140 -0.47558618 -0.05898754 10.2791424 -1.2785850 -1.881395391 -7.0972730 0.283137062 11.300423 -5.42201881 7.69205240 3.6647710
29 -0.14796844 -0.31242843 -7.13439956 8.8376481 13.4659132 1.461275344 4.1133381 2.784203145 12.496497 0.41425657 6.27234388 3.2425929
30 0.33267383 0.07562561 4.30418636 11.5135055 -5.5710269 0.595018978 20.2956727 -1.999030542 23.338891 1.79473828 25.14227894 3.5624672
31 -0.13135999 0.03429504 3.12945679 -1.7988365 -0.8664450 -0.925567331 -3.7275570 -3.950239410 7.792904 -2.94586593 -4.80659759 -5.1385471
32 -0.65278805 -0.24207506 -0.80329023 -1.5381825 -7.0147661 -1.371024797 11.1363243 -0.703554423 9.848548 0.77097874 -0.01193523 2.0874871
33 -0.27298162 0.36527044 -0.44873371 -3.2108142 15.4038635 5.626084802 7.3734731 -0.818813872 -2.329578 -1.22258273 5.73140635 7.6681611
34 0.24697363 0.04004560 3.55251026 10.9369448 17.4436080 4.964061402 -4.1149183 -0.594522702 30.979488 1.34426338 10.79636312 3.7373761
35 -0.23005566 0.07016680 8.61098096 7.2749938 6.1983372 -1.931047305 11.2845415 -0.255800684 -12.768165 0.65177004 7.72055325 -9.8395187
36 0.07745730 -0.07007581 4.21970890 16.3408506 13.6502613 -2.764005594 4.7150426 -3.352393845 7.726116 1.05046858 -11.41243533 -2.5015196
37 -0.68399493 0.23974508 -0.17544534 -5.5184731 5.8961029 -4.510778693 17.5402976 4.658695314 3.495335 4.32696570 6.21866892 2.9641552
38 -0.04013683 -0.78642712 -3.96729208 3.4475599 -1.2403075 2.536697158 -7.7241472 4.334766041 -9.963346 -0.64687173 17.34032967 1.8524765
39 -0.44495174 -0.19879868 1.92668453 6.8470802 21.4526006 0.455531935 27.9513567 -1.370725185 1.955942 3.59422972 24.79601058 -4.6690074
40 -0.13325651 -0.17514241 -2.82513210 21.0013199 -2.2907174 -1.494103403 18.4596623 2.297606605 -2.724228 2.31410400 0.75443901 0.1896653
41 -0.04049955 -0.30950401 1.08764034 12.0828373 3.2890383 5.742280231 -11.8575537 1.698274301 -2.021231 1.42562103 0.06413767 2.3617709
42 0.11173966 -0.66458170 7.85442282 9.1662041 30.2460296 1.990946110 16.4452737 5.687569677 11.302004 8.06994470 23.60159352 -3.6748499
43 0.22047452 -0.53158026 0.50466780 19.9152823 8.9427850 -0.637162403 11.3976456 4.603380514 8.462772 -1.49806588 15.98236455 2.5163547
44 -0.36319770 -0.22408093 2.86754885 1.5941018 -7.0354188 0.740816157 5.6042852 -1.145312539 -4.309770 -4.60556357 8.99063162 4.1639967
45 -0.45275458 -0.08379418 -5.95422943 16.4861889 15.9877620 -0.807411042 8.0873218 4.025147480 -3.494243 1.36140592 0.17167116 0.5730415
46 -0.02849445 -0.22411911 3.18637465 7.3235045 12.1141402 -2.049762449 -5.7373841 1.660312041 16.389530 4.32823877 2.31488480 -1.0958932
47 -0.46860175 -0.13260285 4.40493794 8.4949938 3.9516605 -1.243255229 -1.6795379 -0.013959038 4.140808 -3.39817037 4.27670204 -1.6862091
48 -0.41927264 -0.70467223 3.69590189 -6.4179034 -2.8701968 2.692561594 20.7038768 0.392052464 -2.993030 1.25742496 -5.18694095 -6.7182529
49 -0.02718469 -0.35311492 1.12532546 0.4862352 0.3023580 -1.603408864 1.2115986 0.845596944 9.048511 3.92056012 -8.67131197 -2.3896462
50 -0.32380034 0.06106854 3.30870522 -4.9429947 15.9727621 -0.159746543 7.7858779 1.608172511 4.614853 1.15746997 -3.63746568 -1.5704711
现在我想创建一个新的data.frame,它是基因型和表型的组合。特别地,一列是第一标记的基因型(在markerinfo中),下一列是表型中的相应表型。我想对markerinfo中的所有标记做这个。但是正如您所看到的,有一些重复形式的标记。然而,这些应该被视为不同的标记并且仍然具有列。由于数据的进一步处理,我需要这种交替形式。
如果这有助于您回答我的问题,请提前致谢
答案 0 :(得分:1)
我不确定我是否理解正确。您需要了解如何创建minimal reproducible example,特别是如何使用dput
。
我调用了data.frames markerinfo
,genotype
,phenotype
并仅使用了一小部分数据进行测试。为了使我的解决方案起作用,markerinfo中的每个基因型和表型必须存在于相应的data.frames中。 (因此,我不得不改变markerinfo中的表型,使其适用于我用于测试的简化数据集。)
result <- lapply(seq_along(markerinfo$marker),function(i) {
x <- as.character(markerinfo$marker[i])
res <- cbind(genotype[,x],phenotype[,as.character(markerinfo[i,"pheno"])])
colnames(res) <- c(paste('geno',x,sep="_"),paste('pheno',as.character(markerinfo[i,"pheno"]),sep="_"))
res
}
)
result <- do.call('cbind',result) #combine lists
head(result)
geno_c3m22 pheno_CACNA1E geno_c3m22 pheno_CACNA1F geno_c3m16 pheno_CACNA1G geno_c3m20 pheno_RAPGEF2
[1,] 2 0.053503367 2 -0.05512395 2 -0.16406024 2 -0.247595001
[2,] 2 -0.296400594 2 -0.14167491 2 -0.28751925 2 0.076554542
[3,] 2 0.001312523 2 -0.33078461 2 -0.84388147 2 -0.327202333
[4,] 1 -0.138671725 1 0.15734291 1 -0.04136305 1 -0.007847655
[5,] 1 -0.453451438 1 -0.23904476 2 -0.34506117 1 -0.288891373
[6,] 1 -0.186128793 1 0.12046537 2 -1.45824366 1 -0.819438873
#this is a matrix, use as.data.frame to turn it into a data.frame