聚类距离矩阵

时间:2017-11-14 16:39:59

标签: r

我有一个商店之间距离的数据框,我想生成一个对象(列表,数据框,矩阵),它只显示那些距离彼此不到5英里的商店。

foo <- structure(list(`Store 10` = c(97.182714060764, 0, 104.545505520858,120.848327689344, 21.4956940498461, 71.2102784197574, 9.17403190899889,232.086794775442, 43.8173227163331, 116.039010056627),  
                      `Store 100` = c(74.2475604028815,23.3746751242071, 81.1712781831004, 144.120931315268, 23.4110542291118,94.4577722550024, 31.5739132041779, 209.492371721166, 66.6219804313243,92.7938789352653),  
                      `Store 101` = c(19.0839143178718, 104.545505520858,0, 225.069522157464, 96.7190014732743, 175.476702723702, 112.459326421784,133.381899232519, 147.25396306609, 15.0815963235646),  
                      `Store 11` = c(71.2541974994427,26.3632751561921, 78.1889204614728, 147.127665374137, 24.9756132579165,97.4001827503847, 34.5816273110414, 206.517729238781, 69.5004052925104,89.8749246302702),  
                      `Store 113` = c(47.0881131319699, 50.6021433483968,54.2297393980493, 171.433305152348, 43.4877656302823, 121.27129019099,58.9080280322994, 182.467788036299, 93.0266775510096, 66.6478219738416),  
                      `Store 114` = c(19.3082927142542, 103.863224882231, 0.902204635805178,224.353450878124, 96.1678237911265, 174.82195092457, 111.752223369642,134.253268603651, 146.61996769538, 15.2076513974641),  
                      `Store 115` = c(46.1022549798483,139.935108222076, 35.5378432580255, 260.571940423921, 131.050291660978,210.672320747685, 147.943684720518, 100.604144112037, 182.304038294648,28.0600979672013),  
                      `Store 116` = c(115.977910525396, 22.2743738090946,124.975555327727, 102.631253530033, 31.2636483056516, 50.7113682121305,18.9828219549928, 249.513008836821, 22.2791136562013, 137.099156498485),  
                      `Store 121` = c(46.8649813497236, 138.05949112722, 33.6309330793517,258.355746842495, 130.216167069666, 209.073236612232, 145.841428480987,106.026865528358, 180.880981791045, 23.5225484914477),  
                      `Store 122` = c(105.765734973956,9.17403190899889, 112.459326421784, 112.635113034315, 29.7123946609901,64.2530835558693, 0, 240.864256496468, 38.1560918075898, 123.514728759801),  
                      `Store 123` = c(40.3098694204528, 133.529478517196, 29.0974945685631,254.144085030474, 124.817814759525, 204.30698545979, 141.519160181814,106.485062095671, 175.963360773997, 22.2402993792639),  
                      `Store 124` = c(15.4826131889244,109.72589102537, 10.6559300294596, 230.562026431413, 100.032138241845,180.057734012961, 117.996983784268, 125.132767519462, 151.574939557027,20.7774566354144),  
                      `Store 126` = c(80.4918388261617, 20.1645024607666,90.2108352624732, 137.940344444399, 8.19173113521019, 86.1818977331406,29.2603494697063, 214.189063275208, 57.5661773515707, 102.98401126524),  
                      `Store 127` = c(50.5707899850002, 47.9998858006402, 56.5458773807153,168.658302706349, 42.7349808287988, 119.013256474241, 56.0276915534435,185.942422263827, 90.979153440465, 68.3777607965505),  
                      `Store 128` = c(62.3985613534241,156.467009507205, 51.9662381582155, 277.034745305523, 147.628704344456,227.253259800475, 164.424437950093, 87.7741708055936, 198.897034347146,42.853904907684),  
                      `Store 129` = c(44.4280683852888, 53.1076715622684,54.7594044775595, 173.567416520927, 42.09009359735, 122.269218220088,61.9327484138037, 178.979190967292, 93.684829649538, 68.3502152424742),  
                      `Store 130` = c(29.6627438540889, 121.877375024469, 17.5379868044159,242.512526852249, 113.273456996737, 192.656341703268, 129.882659850672,116.636306650557, 164.32413853956, 14.5836446177209),  
                      `Store 131` = c(42.5311323410154,137.779593313915, 34.1439587366749, 258.570280063638, 128.147397896773,208.229343539775, 145.950719450894, 99.9856701001915, 179.755056696375,29.1673894333183),  
                      `Store 132` = c(155.558743492221, 60.771528260534,164.669885634013, 65.0176561457482, 69.959758550586, 11.3767524543355,54.3203426272865, 288.338559299794, 17.5083349593977, 176.63102062546),  
                      `Store 133` = c(50.8336976425147, 144.449880156622, 39.9580651232559,265.02740840713, 135.720410143754, 215.24691301159, 152.412539463999,97.5389327984704, 186.904554971329, 31.5227184037659),  
                      `Store 135` = c(63.3313266209041,157.175042409662, 52.6467805600477, 277.701522855422, 148.458750384611,228.000622471795, 165.103767022962, 87.8385721010536, 199.664633999748,43.2605181145178),  
                      `Store 136` = c(61.8710249192055, 154.122020212753,49.6640907492411, 274.390910797956, 146.117217151602, 225.128094850195,161.895945075365, 93.5747028772301, 196.917181955845, 39.0757329765446),  
                      `Store 137` = c(103.313457349294, 17.3461827402428, 113.229054795412,116.112422661667, 17.7120593551046, 63.5719949243665, 20.4028086903726,236.187273346596, 34.8714799448828, 125.874876880014),  
                      `Store 139` = c(71.8160418260827,164.107026385352, 59.7067114286829, 284.279664826551, 156.194082461646,235.146144930092, 171.835462193164, 87.4721917453367, 206.95916222963,48.7051425613191),  
                      `Store 14` = c(69.9026102953175, 27.6682921924945,76.8975949005597, 148.453900730172, 25.5703428825346, 98.6613132535166,35.9228707805444, 205.163394506493, 70.7179161568892, 88.638643540865),  
                      `Store 141` = c(160.447782224841, 65.2717814365252, 169.388864785603,59.9444789236008, 74.9450028320972, 6.30907948029094, 58.5421265869609,293.360566048771, 22.4271238094327, 181.242078615482),  
                      `Store 143` = c(94.4967558026401,16.3844028106868, 104.624495877666, 124.844515480636, 8.99230765291032,72.4097871621613, 22.9930146589562, 227.386414291682, 43.7102809488183,117.434599522384),  
                      `Store 144` = c(30.6406755152047, 68.6112712822058,44.4695702684719, 188.558533806214, 55.6147674023494, 136.671637702601,77.5500247906599, 163.646263814946, 107.983907652985, 59.1750702503532),  
                      `Store 145` = c(116.634237264487, 23.6359859109202, 125.843931060261,102.259873126813, 31.5514229455087, 50.039873981195, 20.6409773826946,249.951334197986, 21.4569059128841, 138.065135950694),  
                      `Store 146` = c(49.0568193512663,54.311278216063, 51.5682497967442, 173.872187121451, 51.8366521189428,125.496883714123, 61.5757017052046, 183.451756458655, 97.9724963791237,61.9504010810814),  
                      `Store 147` = c(0, 97.182714060764, 19.0839143178718,217.908876952855, 85.9859121607294, 166.67126390107, 105.765734973956,135.391012347645, 138.050987597536, 33.6823000691004),  
                      `Store 148` = c(48.2299284841927,53.7142932078625, 51.5598052976402, 173.640099206422, 50.4421662885367,124.924567331259, 61.1836277867489, 182.958179140963, 97.2494257434835,62.3601665165924),  
                      `Store 149` = c(49.9477288326237, 52.1431794480886,53.2674613906208, 171.968693905148, 49.3117412727633, 123.350162356965,59.5479342705133, 184.700460684605, 95.7315747878528, 63.9749611826139),  
                      `Store 15` = c(82.5768888008737, 15.4683626243912, 89.2381403030532,135.920084787888, 21.9407747294326, 86.6764572064895, 23.3053648689151,217.826144766742, 59.181641916233, 100.588426031137),  
                      `Store 150` = c(111.470597382221,14.5119998977806, 118.221849873196, 106.872183476945, 33.6852827380805,58.7080741940326, 5.76337578744118, 246.512942912896, 33.2309002398316,129.247939288897),  
                      `Store 151` = c(85.5164627172282, 21.0650021470382,89.719717608509, 136.048733561359, 33.5514294236898, 89.3823249007233,25.3616871032807, 220.808335030956, 63.4667089762883, 99.7490148934809),  
                      `Store 152` = c(65.7333609050899, 159.708693014139, 55.1846211658909,280.242160041282, 150.943739032955, 230.523732896797, 167.642654764196,85.7426951335072, 202.180426706117, 45.7642994377334),  
                      `Store 153` = c(59.3579242287549,149.610092014953, 45.6143412842972, 269.559143541198, 142.330605461009,220.738288755992, 157.22437780625, 100.319798887199, 192.668333201516,33.8384127325631),  
                      `Store 154` = c(14.6177046456285, 105.321597967839,5.80210070409739, 226.091584853407, 96.3550552882973, 175.921089463583,113.468746014001, 130.422441769589, 147.528879548255, 19.1326831571266),  
                      `Store 155` = c(98.0521250589665, 14.9615837614282, 107.891590694071,121.044929404276, 12.842867538134, 68.7318498691966, 20.3433651716831,231.147101768248, 40.0455203560419, 120.545097753848),  
                      `Store 158` = c(127.28518481773,30.2013867691535, 134.667667307237, 90.6598544948954, 45.3406347212269,42.0113596970615, 22.4099907573838, 261.906676938723, 18.6101002948444,145.890690285015),  
                      `Store 159` = c(67.6749186168928, 158.91047585088,54.7277366056853, 278.919460342222, 151.389358118033, 230.013706144037,166.557956365005, 93.0065500154447, 201.902095297973, 43.2119219139315),  
                      `Store 160` = c(110.120232119226, 20.8254695717587, 119.897083434758,109.392676953945, 24.4967523202215, 56.7555673594198, 20.9182993439403,242.976497116235, 28.0547337715745, 132.430245082595),  
                      `Store 161` = c(138.113572784299,45.0931604978753, 147.748517674391, 82.7382855546652, 52.2879796050827,29.2315784133779, 40.03378203141, 270.539048139633, 3.72405642504832,160.050898616871),  
                      `Store 162` = c(39.5318874970135, 58.2426177248329,46.7674666037364, 179.080302234251, 50.3530377561357, 128.818374320699,66.5595692995086, 174.922803603218, 100.509780214086, 59.5159959177498),  
                      `Store 163` = c(113.898151873892, 21.8503465903741, 123.256785979153,105.115182928792, 28.6934110323499, 52.7968063588392, 19.914038455521,247.118360982377, 24.1551906075442, 135.568043716944),  
                      `Store 164` = c(167.296800589537,72.5538864322338, 176.493531722362, 54.7266951318064, 81.5741222821151,4.06885914637227, 65.9373166073689, 299.806169163016, 29.2845708803529,188.451665473381),  
                      `Store 165` = c(100.861353629287, 18.3110449793727,104.973470818329, 121.439421883486, 38.4023517429513, 76.6187217512178,16.1847822790123, 236.179406006191, 52.7160110816438, 114.687045845975),  
                      `Store 166` = c(84.2309696787776, 26.0860582793184, 87.4029960514953,139.227141903611, 38.1811729600301, 93.434701169323, 29.8197291133567,219.249743646815, 67.9751869268833, 96.8901622223067),  
                      `Store 167` = c(42.6659873965625,54.71184818961, 52.7896560771485, 175.274216597181, 44.0219182175731,124.078866519639, 63.4825184989626, 177.390013796269, 95.5146942756369,66.3595384524349),  
                      `Store 168` = c(27.9588076795691, 69.7279066991086,40.3368579277696, 190.19369821024, 58.0608388931474, 138.737127622791,78.5070370487016, 162.366317609087, 110.102409513181, 54.8303582440215),  
                      `Store 169` = c(69.3159383038625, 27.9806959835842, 76.7505745526877,148.828132946066, 24.427921667524, 98.7337533354309, 36.4499470061253,204.475568144805, 70.6516437376385, 88.7015577637252),  
                      `Store 170` = c(21.5182328406625,81.0766121041097, 23.5040887504589, 201.7123753104, 73.5685355110635,151.972652223415, 89.0780912882125, 154.463389583329, 123.763124828067,36.3513987268101),  
                      `Store 171` = c(44.113714476827, 141.170390840861,40.7099024063727, 261.969465961018, 129.923502112083, 210.767960750873,149.643621219947, 92.8741873982887, 182.130236923797, 39.1531976152106),  
                      `Store 172` = c(19.7849976772945, 81.7327152729014, 23.0557408490977,202.456573054471, 73.7396811249913, 152.509772689368, 89.8263447104721,153.235986420409, 124.231532446728, 36.3930683039177),  
                      `Store 173` = c(18.0896049763375,81.7180794297641, 23.7146422241885, 202.531152805935, 73.0324966127671,152.282200543921, 89.9452137081293, 152.432264250142, 123.912487479355,37.6141760528144),  
                      `Store 174` = c(36.8897611134, 134.055684768267,35.3860918685918, 254.798580870764, 122.521779120797, 203.446863653305,142.593386316348, 99.2011320960102, 174.79194894808, 36.3508939538918),  
                      `Store 175` = c(19.4055088776882, 116.574724359947, 23.3648681171702,237.25992572555, 104.929272535089, 185.845524690095, 125.170594980623,116.077864702495, 157.189185893232, 31.3550210113149),  
                      `Store 176` = c(122.111235017339,31.0308415808054, 131.964915536305, 98.2014379071899, 36.2667125370514,45.0713484742342, 28.1298214696256, 254.596980227275, 16.5153465948402,144.457436271883),  
                      `Store 177` = c(174.312564632948, 79.1922090280055,183.340294466275, 47.8073182354175, 88.6625262979693, 8.09591435748952,72.3206532781363, 306.943427288542, 36.2623491601668, 195.185377885561),  
                      `Store 178` = c(124.61219657824, 29.2189874552703, 133.185169837572,93.7227786978209, 40.2544721298839, 42.2933454932431, 23.5771031889714,258.394559593159, 14.6785036558556, 145.039824993218),  
                      `Store 179` = c(24.061240178573,73.6283030875174, 32.5698473716518, 194.474670260206, 64.2598509447223,143.868493927243, 82.0380354121153, 159.429322108816, 115.415891099251,46.4566844521991),  
                      `Store 180` = c(44.9701847904077, 53.5741556808663,56.5028532974761, 173.52782156235, 41.0332449596439, 121.809685121786,62.5506909595459, 178.713172704501, 93.1490182636026, 70.441327010977),  
                      `Store 181` = c(111.967567861059, 15.3395480941109, 118.456513677175,106.613028699201, 35.0444361312221, 58.9787865880595, 6.25161265482528,247.099102496894, 34.0064929129624, 129.338722956737),  
                      `Store 182` = c(60.3456838723146,157.165746321455, 54.8712719155892, 278.007492402975, 146.264575168245,227.01038283941, 165.54630457556, 78.9129302783064, 198.39647719976,49.9351821713357),  
                      `Store 183` = c(13.4908806737511, 106.989824235947,9.21244068502985, 227.822410878512, 97.4026538853887, 177.355731406986,115.251274704921, 127.837556171709, 148.88531616473, 21.2420515177377),  
                      `Store 184` = c(111.033225406542, 19.2764979102658, 120.345826022698,107.824773824757, 26.0137323203271, 55.6456779424236, 18.2181155011756,244.358639647822, 27.0332546214697, 132.655884995622),  
                      `Store 185` = c(121.308917445053,26.4252993976045, 130.039503153969, 97.124054050421, 36.8181137758406,45.4805165537354, 21.5036756085157, 255.000788916903, 17.4208150256445,141.995038580212),  
                      `Store 186` = c(84.839269969394, 21.5242708074613,95.4923419326264, 134.770659233404, 1.2764208987712, 82.2799328459307,29.9352010285124, 217.469820029272, 53.5799208540953, 108.608440764191),  
                      `Store 187` = c(70.762830554532, 26.7493232717837, 77.8264470408527,147.549192114017, 24.7936684973839, 97.7236536067102, 35.0395450196894,206.002392522627, 69.7738084636148, 89.5813570895854),  
                      `Store 188` = c(73.4914682940968,166.142669957365, 61.6880533608055, 286.372456277449, 158.08397622017,237.153772934312, 173.900880020558, 85.3267010710687, 208.939606223087,50.8679871357349),  
                      `Store 189` = c(30.6335264648226, 123.256891318455,18.9764035968927, 243.911262897971, 114.550626876199, 194.008128743653,131.27901530561, 115.178276808933, 165.660950927686, 15.68699143228),  
                      `Store 19` = c(23.3642987684607, 78.6445238327238, 25.9240409323312,199.275549425542, 71.2620727787222, 149.554161877786, 86.6413245639711,156.793548788537, 121.358188826921, 38.6120813160024),  
                      `Store 190` = c(24.8953566793903,117.245571156207, 13.3340327832417, 237.944432716928, 108.445877146219,187.947611720127, 125.309321393313, 120.152382559651, 159.583855382627,14.6647069749799),  
                      `Store 191` = c(155.549777905836, 59.2045930103401,163.721983356225, 62.8685411134829, 70.9404199229136, 12.9854946588728,51.8374805070557, 289.315677754038, 19.3149032304898, 175.194340788389),  
                      `Store 192` = c(91.4872714349676, 20.7420409870123, 102.303830906892,128.795763082887, 5.5849073536186, 75.9919896582289, 27.8657918252687,223.671926751966, 47.3273985563995, 115.43062460952),  
                      `Store 193` = c(141.719380784307,44.7308064777817, 149.21549633528, 76.1901979874281, 58.6478661940372,28.2986343042698, 36.8888272114097, 276.148618719698, 14.5982071991189,160.401940554441),  
                      `Store 194` = c(48.514585801489, 53.9192393293824,51.5507325193362, 173.721059423255, 50.9351331055158, 125.126181046054,61.3161015133771, 183.130645867563, 97.5039715964655, 62.2037250260579),  
                      `Store 195` = c(164.817466984655, 68.4273774676872, 172.961113991137,53.7638946100393, 80.0923517591417, 6.92931132757607, 60.9386983862209,298.518399895709, 27.9982779422079, 184.375889358264),  
                      `Store 196` = c(57.8791543420262,39.8731109468306, 64.7367364412644, 160.662187066822, 34.7483617119882,110.75845281183, 48.0982056977083, 193.235019566556, 82.6699385366847,76.7036279641455),  
                      `Store 197` = c(82.3340701244326, 24.430876802672,93.3620542941436, 137.6952453344, 3.89925888328242, 85.0666101440906,32.9745290918747, 214.623799032827, 56.3779006738775, 106.651209674791), 
                      `Store 198` = c(61.7331430932174, 41.6180605526713, 74.0615309657223,158.728662838499, 24.966286291908, 106.183761957946, 50.7830769428203,193.514274891317, 77.4948060082806, 88.0144312091132),  
                      `Store 199` = c(166.67126390107,71.2102784197574, 175.476702723702, 53.7367961521279, 81.2330368742957,0, 64.2530835558693, 299.662194368447, 28.7008518753862, 187.234252564455), 
                      `Store 2` = c(71.4306146651704, 26.1188858912486, 78.4436621201813,146.904747423482, 24.5812050041696, 97.1253757139686, 34.380881492236,206.676269143349, 69.2034635209456, 90.1621318945159), 
                      `Store 200` = c(138.050987597536,43.8173227163331, 147.25396306609, 81.6884783765538, 52.5372484426156,28.7008518753862, 38.1560918075898, 270.994160457313, 0, 159.343872952503), 
                      `Store 201` = c(167.299937831438, 71.0085926507406, 175.530197092849,51.5242300593162, 82.435859482383, 5.77433520197501, 63.5665101049999,300.893950302255, 30.1648913107489, 186.980778244732), 
                      `Store 202` = c(75.8142152145889,168.978523628256, 64.4657604762506, 289.293568083503, 160.696477104858,239.941616470381, 176.782830387055, 82.1915792024463, 211.68656304804,53.9228716088697), 
                      `Store 203` = c(84.4342251533454, 22.3413358736533,95.2178146219974, 135.345773392241, 1.55941180174149, 82.7893845620659,30.7454280782317, 216.929767592851, 54.0927852258926, 108.390557720654), 
                      `Store 204` = c(22.1143205044024, 114.156359921168, 10.5669818888741,234.871499237087, 105.333331209187, 184.839958871956, 122.236961768806,122.814937270634, 156.471470077292, 14.94366299403), 
                      `Store 205` = c(122.1867570939,35.6035124272749, 133.012362035619, 100.894788979297, 36.3496927542645,47.205327605463, 34.2399762735442, 253.324976689857, 20.2203608687206,145.950349598117), 
                      `Store 206` = c(70.1191986671587, 167.111567817173,65.0342316301412, 287.93466221017, 155.89462732924, 236.774146245167,175.536143580105, 68.9290424392404, 208.133198902687, 59.7418624930726), 
                      `Store 207` = c(88.5687945825953, 20.1658244721324, 99.2013792438283,131.220345824945, 2.60896587403033, 78.6245234271278, 28.0000435453275,221.084868654116, 49.929251874617, 112.276065981859), 
                      `Store 208` = c(85.9859121607294,21.4956940498461, 96.7190014732743, 133.808566486628, 0, 81.2330368742957,29.7123946609901, 218.480538056125, 52.5372484426156, 109.857440510197), 
                      `Store 209` = c(121.663640082533, 28.9006139146935, 131.070615054781,97.7229173210449, 36.1960660065879, 45.0888689432883, 25.2658849461922,254.676555811973, 16.3993052713823, 143.353549283483), 
                      `Store 21` = c(36.0480404047006,61.9873611681417, 42.9777748186856, 182.813207902126, 54.0670953074946,132.604605615094, 70.2611511460531, 171.413791566702, 104.300827164642,55.7904226028449), 
                      `Store 210` = c(141.172490571705, 47.590467181754,150.654610539172, 79.4675863369946, 55.4174448807273, 25.9907325466536,42.1310486296248, 273.73242009186, 4.06432884804506, 162.867201320882), 
                      `Store 211` = c(195.549857773211, 99.0907594141363, 203.636015465996,24.5734528986502, 110.560998346534, 29.5859891297109, 91.3903210186264,329.041527102902, 58.0778758968437, 214.904399633133),  
                      `Store 212` = c(19.8758322224963,79.5858453380513, 35.6533601753144, 199.72077031221, 66.8023296885385,147.875689075413, 88.4567582084607, 152.550832647225, 119.187833806082,50.6967832261861),  
                      `Store 213` = c(208.422391774923, 111.355422226041,215.585707126769, 9.49312702759228, 124.417581698746, 44.7662840289739,103.146190321542, 342.670576447407, 72.4193928009537, 226.294313616523),  
                      `Store 214` = c(57.4796622794928, 154.555666730667, 53.3509827699372,275.352996387969, 143.19987077126, 224.106641472437, 163.024900930719,80.036615273364, 195.458347761762, 49.6929091134769)), 
                .Names = c("Store 10","Store 100", "Store 101", "Store 11", "Store 113", "Store 114","Store 115", "Store 116", "Store 121", "Store 122", "Store 123","Store 124", "Store 126", "Store 127", "Store 128", "Store 129","Store 130", "Store 131", "Store 132", "Store 133", "Store 135","Store 136", "Store 137", "Store 139", "Store 14", "Store 141","Store 143", "Store 144", "Store 145", "Store 146", "Store 147","Store 148", "Store 149", "Store 15", "Store 150", "Store 151","Store 152", "Store 153", "Store 154", "Store 155", "Store 158","Store 159", "Store 160", "Store 161", "Store 162", "Store 163","Store 164", "Store 165", "Store 166", "Store 167", "Store 168","Store 169", "Store 170", "Store 171", "Store 172", "Store 173","Store 174", "Store 175", "Store 176", "Store 177", "Store 178","Store 179", "Store 180", "Store 181", "Store 182", "Store 183","Store 184", "Store 185", "Store 186", "Store 187", "Store 188","Store 189", "Store 19", "Store 190", "Store 191", "Store 192","Store 193", "Store 194", "Store 195", "Store 196", "Store 197","Store 198", "Store 199", "Store 2", "Store 200", "Store 201","Store 202", "Store 203", "Store 204", "Store 205", "Store 206","Store 207", "Store 208", "Store 209", "Store 21", "Store 210","Store 211", "Store 212", "Store 213", "Store 214"), 
                row.names = c("Store 147","Store 10", "Store 101", "Store 434", "Store 208", "Store 199","Store 122", "Store 593", "Store 200", "Store 502"), 
                class = "data.frame") 
==X==============================================================X==

1 个答案:

答案 0 :(得分:0)

如果你的意思是将你的数据子集化为小于或等于5的元素,你可以使用tidyverse:

library(tidyverse)

foo %>% 
    rownames_to_column('store1') %>%    # add rownames as variable
    gather(store2, distance, -store1) %>%    # reshape to long form
    filter(distance <=5,    # drop higher distances and same-store pairs
           distance != 0)
#>      store1    store2  distance
#> 1 Store 101 Store 114 0.9022046
#> 2 Store 200 Store 161 3.7240564
#> 3 Store 199 Store 164 4.0688591
#> 4 Store 208 Store 186 1.2764209
#> 5 Store 208 Store 197 3.8992589
#> 6 Store 208 Store 203 1.5594118
#> 7 Store 208 Store 207 2.6089659
#> 8 Store 200 Store 210 4.0643288

或在基础R:

foo <- as.matrix(foo)    # `which` will coerce anyway, and matrix subsetting is more useful later
indices <- which(foo <= 5 & foo != 0, arr.ind = TRUE)

data.frame(
    store1 = rownames(foo)[indices[, 'row']],
    store2 = colnames(foo)[indices[, 'col']],
    distance = foo[which(foo <= 5 & foo != 0)],
    stringsAsFactors = FALSE
)
#>      store1    store2  distance
#> 1 Store 101 Store 114 0.9022046
#> 2 Store 200 Store 161 3.7240564
#> 3 Store 199 Store 164 4.0688591
#> 4 Store 208 Store 186 1.2764209
#> 5 Store 208 Store 197 3.8992589
#> 6 Store 208 Store 203 1.5594118
#> 7 Store 208 Store 207 2.6089659
#> 8 Store 200 Store 210 4.0643288