我使用R中的grep()
命令来通过data.frame
的列。在本专栏中,我在表格中有不同的隔离名称,如数据的子集
Iso1_Iso2 Mean
1 A1-A1 0.002233720
2 A1-A2 0.326511506
3 A1-A4 0.336006087
4 A1-A5 0.044498806
5 A1-B1 0.048086785
6 A1-B10 0.050301924
7 A1-B12 0.037419014
8 A1-B15 0.044474378
我想选择内部有“B1”隔离线的所有线路。但是使用
grep("B1", Distance_no_separate$Iso1_Iso2)
我也获得了里面有“B10”,“B12”,“B15”隔离名称的行。我必须做些什么才能grep()
确切的字?
这是我的data.frame
的dput()
Distance_no_separate <- structure(list(Iso1_Iso2 = c("A1-A1", "A1-A2", "A1-A4", "A1-A5",
"A1-B1", "A1-B10", "A1-B12", "A1-B15", "A1-B2", "A1-B3", "A1-B4",
"A1-C1", "A1-C2", "A1-C3", "A1-C4", "A1-C5", "A1-CAN", "A1-D1",
"A1-D3", "A1-D4", "A2-A2", "A2-A4", "A2-A5", "A2-B1", "A2-B10",
"A2-B12", "A2-B15", "A2-B2", "A2-B3", "A2-B4", "A2-C1", "A2-C2",
"A2-C3", "A2-C4", "A2-C5", "A2-CAN", "A2-D1", "A2-D3", "A2-D4",
"A4-A4", "A4-A5", "A4-B1", "A4-B10", "A4-B12", "A4-B15", "A4-B2",
"A4-B3", "A4-B4", "A4-C1", "A4-C2", "A4-C3", "A4-C4", "A4-C5",
"A4-CAN", "A4-D1", "A4-D3", "A4-D4", "A5-A5", "A5-B1", "A5-B10",
"A5-B12", "A5-B15", "A5-B2", "A5-B3", "A5-B4", "A5-C1", "A5-C2",
"A5-C3", "A5-C4", "A5-C5", "A5-CAN", "A5-D1", "A5-D3", "A5-D4",
"B1-B1", "B1-B10", "B1-B12", "B1-B15", "B1-B2", "B1-B3", "B1-B4",
"B1-C1", "B1-C2", "B1-C3", "B1-C4", "B1-C5", "B1-CAN", "B1-D1",
"B1-D3", "B1-D4", "B10-B10", "B10-B12", "B10-B15", "B10-C1",
"B10-C2", "B10-C3", "B10-C4", "B10-C5", "B10-CAN", "B10-D1",
"B10-D3", "B10-D4", "B12-B12", "B12-B15", "B12-C1", "B12-C2",
"B12-C3", "B12-C4", "B12-C5", "B12-CAN", "B12-D1", "B12-D3",
"B12-D4", "B15-B15", "B15-C1", "B15-C2", "B15-C3", "B15-C4",
"B15-C5", "B15-CAN", "B15-D1", "B15-D3", "B15-D4", "B2-B10",
"B2-B12", "B2-B15", "B2-B2", "B2-B3", "B2-B4", "B2-C1", "B2-C2",
"B2-C3", "B2-C4", "B2-C5", "B2-CAN", "B2-D1", "B2-D3", "B2-D4",
"B3-B10", "B3-B12", "B3-B15", "B3-B3", "B3-B4", "B3-C1", "B3-C2",
"B3-C3", "B3-C4", "B3-C5", "B3-CAN", "B3-D1", "B3-D3", "B3-D4",
"B4-B10", "B4-B12", "B4-B15", "B4-B4", "B4-C1", "B4-C2", "B4-C3",
"B4-C4", "B4-C5", "B4-CAN", "B4-D1", "B4-D3", "B4-D4", "C1-C1",
"C1-C2", "C1-C3", "C1-C4", "C1-C5", "C1-D1", "C1-D3", "C1-D4",
"C2-C2", "C2-C3", "C2-C4", "C2-C5", "C2-D1", "C2-D3", "C2-D4",
"C3-C3", "C3-C4", "C3-C5", "C3-D1", "C3-D3", "C3-D4", "C4-C4",
"C4-C5", "C4-D1", "C4-D3", "C4-D4", "C5-C5", "C5-D1", "C5-D3",
"C5-D4", "CAN-C1", "CAN-C2", "CAN-C3", "CAN-C4", "CAN-C5", "CAN-CAN",
"CAN-D1", "CAN-D3", "CAN-D4", "D1-D1", "D1-D3", "D1-D4", "D3-D3",
"D3-D4", "D4-D4"), Mean = c(0.00223372023478488, 0.326511506251481,
0.336006086921219, 0.0444988056126707, 0.0480867845389803, 0.0503019236019748,
0.0374190142347097, 0.044474378005598, 0.0495784849816714, 0.0376867344270165,
0.0379398897604375, 0.199202292123909, 0.200410050450334, 0.330229533194149,
0.336736047551321, 0.192383188880773, 0.0963655296763318, 0.0452457156018548,
0.0459338875869661, 0.0520404126026609, 0.0138526390807327, 0.277738407973838,
0.326027271922371, 0.329568087515665, 0.328551854053512, 0.328442686320933,
0.325848806029151, 0.325351105074129, 0.333090129724386, 0.33062905751089,
0.351548041828749, 0.35298522688544, 0.278038721695356, 0.280444201259627,
0.347785267127948, 0.317880376701051, 0.331310062984989, 0.334259421551803,
0.33321321720163, 0.00728391756894024, 0.335219063735799, 0.335375425728176,
0.332607795984944, 0.333624302483247, 0.334027396919537, 0.334805995833275,
0.335455392618241, 0.336176687192981, 0.356303015361001, 0.35991484492754,
0.0140578030166058, 0.0144763669722533, 0.361289001237283, 0.322368619083354,
0.339550052850274, 0.334620165238968, 0.334520636092453, 0.00305000075688154,
0.0400897398776824, 0.0402562647662547, 0.0414107144955124, 0.00533124050947717,
0.0391928609558206, 0.0427009237803975, 0.0435719247828981, 0.191082014943474,
0.197090480513609, 0.330060002985445, 0.331576321436942, 0.194190923742177,
0.0987412452322503, 0.0426289828094761, 0.0411839645860355, 0.0493718669337317,
0.00180478198033683, 0.00454773013981058, 0.0400728473448956,
0.0407189164844416, 0.00482284749281307, 0.045823214324788, 0.0445233775660656,
0.195961845095479, 0.195672881728697, 0.333832538512492, 0.334608164905294,
0.195649893475027, 0.0968066707407677, 0.0430605330700204, 0.0434531283254102,
0.0539686262771277, 0.0022627642366692, 0.039420637717289, 0.0422282283194595,
0.194256396504509, 0.195856326510698, 0.330068213529374, 0.335903033931699,
0.194416823513667, 0.0961000771643727, 0.0433900961812807, 0.0427593691418318,
0.0519440981058184, 0.00340435607874443, 0.0390702469624961,
0.197659208886204, 0.198154699676583, 0.327367819084691, 0.332485733577357,
0.19488214965918, 0.100586838253038, 0.0450055381921049, 0.0415899238627063,
0.0519147495479087, 0.00253462935888178, 0.193243216543313, 0.192716414780958,
0.331500798269211, 0.332278217436312, 0.192354218097537, 0.0986226942472296,
0.0426762753334572, 0.0427290342074088, 0.0485044666051026, 0.00492769216876406,
0.0390674431248307, 0.0406523361332636, 0.00268044509675024,
0.0462499761541193, 0.0450677605762003, 0.194849231667258, 0.195399409244883,
0.333084236549372, 0.337895157995945, 0.195224367762397, 0.0968295660915616,
0.0434429045722447, 0.044646027345151, 0.0527555979590115, 0.0463382231880367,
0.00503397088784229, 0.0423027945795776, 0.00186442780875119,
0.00530974368995733, 0.199302539132322, 0.199995474885383, 0.333474261863549,
0.335187241997379, 0.199733796648274, 0.103691542371057, 0.0470613290896341,
0.0471122945287453, 0.0530235459194857, 0.0455508882636425, 0.00681699975100358,
0.0441748944665067, 0.003522575395536, 0.199770392807277, 0.197741744940629,
0.333853257134419, 0.33582505480648, 0.198483330686744, 0.103148545689295,
0.0477440505751682, 0.0445732489871238, 0.055186206944818, 0.00494296128283973,
0.00996509651300943, 0.361098737043685, 0.360763784891108, 0.00925831234565036,
0.200678422180443, 0.197633497229289, 0.197602528974878, 0.0046881978755849,
0.360702907713455, 0.363054305844546, 0.00879489890519423, 0.197861665955482,
0.200169731748693, 0.195047488054228, 0.00719758125685549, 0.0135127552832453,
0.361907005213846, 0.336605263172587, 0.33593078154814, 0.331371565318138,
0.00771869588709974, 0.359861893571362, 0.336656360746836, 0.334253860842037,
0.333018174065755, 0.00442744180502197, 0.199382445122727, 0.197320501995477,
0.191867695619231, 0.184069371910592, 0.188327278515924, 0.319803751206133,
0.320450936911227, 0.184680747074505, 0.0016830999405719, 0.102543989109571,
0.102929829171427, 0.0985319020732606, 0.001966957439715, 0.00322819864061239,
0.0541256629080693, 0.00136154537201564, 0.0531978315034261,
0.00207008479552331)), .Names = c("Iso1_Iso2", "Mean"), row.names = c(NA,
-210L), class = "data.frame")