我有一个object, "a"由空间坐标X和Y组成。物体随着时间的推移而增大。在尺寸增加后,对象" a"现在有了新的空间坐标,我把它称为object "b"。两个对象的坐标值由X值的水平带组成;因此,对于每个对象,每个波段中的Y值是相同的。我需要做的是创建一个包含对象的所有值的新数据框" b"数据框的X值与对象" a"的数据框落在同一个包络内。将对象视为两个不同大小的脚印。我只需要两个足迹共有的数据。 Y值项是每个数据帧中的公共因子,但数据帧中每个Y值的X值范围是变化的。
这是两个对象在绘制时的样子。对象" a"是两个中较小的蓝色和对象" b"是黑色的。
a<-a
b<-b
plot(b$X,b$Y,cex=0.4,pch=19,col="black")
points(a$X,a$Y,cex=0.4,pch=19,col="blue")
注意:每个数据框中都有第三列(&#34; res&#34;)。当建立新的数据帧时,我需要为对象b的那些值继承第三列数据,这些值在对象中是一个足迹。我已使用filter
尝试了dplyr
,但我似乎无法根据另一个数据框的值来过滤一个数据框中的值。
df<-b[b$X <= a$X&a$X <=b$X]
df <- b %>% filter(X<=a$X&a$X>=X)
根据下面的请求,这里是每个对象的前两行,其中多个X值沿着相同的Y值带。如果这是笨重的,请道歉。
a$X a$Y a$res
0.09029928 0.015375 157.2284508
0.09079928 0.015375 155.565961
0.09129928 0.015375 156.033599
0.09179928 0.015375 158.22608
0.09229928 0.015375 161.7861875
0.09279928 0.015375 166.4013949
0.09329928 0.015375 171.8005754
0.09379928 0.015375 177.7508019
0.09429928 0.015375 184.0542401
0.09479928 0.015375 190.5451385
0.09529928 0.015375 197.086916
0.09579928 0.015375 203.569351
0.09629928 0.015375 209.9058749
0.09679928 0.015375 216.0309714
0.09729928 0.015375 221.8976859
0.09779928 0.015375 227.4752458
0.09829928 0.015375 232.7467964
0.09879928 0.015375 237.7072531
0.09929928 0.015375 242.3612742
0.09979928 0.015375 246.7213556
0.10029928 0.015375 250.8060511
0.10079928 0.015375 254.6383205
0.10129928 0.015375 258.2440078
0.10179928 0.015375 261.6504535
0.10229928 0.015375 264.8852414
0.10279928 0.015375 267.9750851
0.10329928 0.015375 270.9448547
0.10379928 0.015375 273.8167481
0.10429928 0.015375 276.6096081
0.10479928 0.015375 279.3383892
0.10529928 0.015375 282.0137753
0.10579928 0.015375 284.641953
0.10629928 0.015375 287.2245411
0.10679928 0.015375 289.7586798
0.10729928 0.015375 292.2372832
0.10779928 0.015375 294.649456
0.10829928 0.015375 296.9810784
0.10879928 0.015375 299.2155606
0.10929928 0.015375 301.3347719
0.10979928 0.015375 303.3201437
0.11029928 0.015375 305.1539521
0.11079928 0.015375 306.8207812
0.11129928 0.015375 308.3091696
0.11179928 0.015375 309.613444
0.11229928 0.015375 310.7357413
0.11279928 0.015375 311.6882223
0.11329928 0.015375 312.49548
0.11379928 0.015375 313.1971451
0.11429928 0.015375 313.8506902
0.11479928 0.015375 314.534437
0.11529928 0.015375 315.3507686
0.08581068 0.017375 135.8921899
0.08631068 0.017375 135.6813081
0.08681068 0.017375 135.7108871
0.08731068 0.017375 136.065192
0.08781068 0.017375 136.8065344
0.08831068 0.017375 137.9778373
0.08881068 0.017375 139.6050362
0.08931068 0.017375 141.6993184
0.08981068 0.017375 144.2592074
0.09031068 0.017375 147.2724963
0.09081068 0.017375 150.718035
0.09131068 0.017375 154.5673762
0.09181068 0.017375 158.7862848
0.09231068 0.017375 163.336116
0.09281068 0.017375 168.1750659
0.09331068 0.017375 173.2593009
0.09381068 0.017375 178.5439689
0.09431068 0.017375 183.9840986
0.09481068 0.017375 189.535391
0.09531068 0.017375 195.1549082
0.09581068 0.017375 200.8016635
0.09631068 0.017375 206.4371191
0.09681068 0.017375 212.0255946
0.09731068 0.017375 217.5345922
0.09781068 0.017375 222.9350431
0.09831068 0.017375 228.2014794
0.09881068 0.017375 233.3121371
0.09931068 0.017375 238.2489946
0.09981068 0.017375 242.9977514
0.10031068 0.017375 247.5477517
0.10081068 0.017375 251.8918586
0.10131068 0.017375 256.0262823
0.10181068 0.017375 259.9503683
0.10231068 0.017375 263.6663496
0.10281068 0.017375 267.1790681
0.10331068 0.017375 270.4956703
0.10381068 0.017375 273.6252813
0.10431068 0.017375 276.5786621
0.10481068 0.017375 279.367856
0.10531068 0.017375 282.0058274
0.10581068 0.017375 284.5060987
0.10631068 0.017375 286.8823904
0.10681068 0.017375 289.1482679
0.10731068 0.017375 291.3168014
0.10781068 0.017375 293.4002421
0.10831068 0.017375 295.4097212
0.10881068 0.017375 297.3549752
0.10931068 0.017375 299.2441021
0.10981068 0.017375 301.0833553
0.11031068 0.017375 302.8769776
0.11081068 0.017375 304.6270808
0.11131068 0.017375 306.3335775
0.11181068 0.017375 307.9941667
0.11231068 0.017375 309.6043809
0.11281068 0.017375 311.1576978
0.11331068 0.017375 312.6457221
0.11381068 0.017375 314.0584417
0.11431068 0.017375 315.384564
0.11481068 0.017375 316.6119359
0.11531068 0.017375 317.7280532
0.11581068 0.017375 318.720664
0.11631068 0.017375 319.5784707
0.11681068 0.017375 320.2919353
0.11731068 0.017375 320.8541934
0.11781068 0.017375 321.2620811
0.11831068 0.017375 321.51728
0.11881068 0.017375 321.6275841
0.11931068 0.017375 321.6082958
0.11981068 0.017375 321.4837525
0.12031068 0.017375 321.2889916
0.12081068 0.017375 321.0715562
0.12131068 0.017375 320.8934492
0.12181068 0.017375 320.8332368
0.12231068 0.017375 320.9883102
0.12281068 0.017375 321.4773073
0.12331068 0.017375 322.4427005
b$X b$Y b$res
0.0455699 0.015375 74.06596721
0.0460699 0.015375 76.4523308
0.0465699 0.015375 78.53219293
0.0470699 0.015375 80.33607583
0.0475699 0.015375 81.89274681
0.0480699 0.015375 83.22928022
0.0485699 0.015375 84.37111818
0.0490699 0.015375 85.34213004
0.0495699 0.015375 86.16467047
0.0500699 0.015375 86.85963646
0.0505699 0.015375 87.44652295
0.0510699 0.015375 87.94347726
0.0515699 0.015375 88.36735239
0.0520699 0.015375 88.733759
0.0525699 0.015375 89.05711629
0.0530699 0.015375 89.35070163
0.0535699 0.015375 89.6266991
0.0540699 0.015375 89.89624682
0.0545699 0.015375 90.16948314
0.0550699 0.015375 90.45559176
0.0555699 0.015375 90.76284569
0.0560699 0.015375 91.09865007
0.0565699 0.015375 91.46958399
0.0570699 0.015375 91.88144114
0.0575699 0.015375 92.33926948
0.0580699 0.015375 92.84740977
0.0585699 0.015375 93.40953312
0.0590699 0.015375 94.02867748
0.0595699 0.015375 94.70728314
0.0600699 0.015375 95.44722718
0.0605699 0.015375 96.24985697
0.0610699 0.015375 97.11602266
0.0615699 0.015375 98.04610876
0.0620699 0.015375 99.04006465
0.0625699 0.015375 100.0974343
0.0630699 0.015375 101.2173848
0.0635699 0.015375 102.3987345
0.0640699 0.015375 103.6399795
0.0645699 0.015375 104.9393198
0.0650699 0.015375 106.2946845
0.0655699 0.015375 107.7037558
0.0660699 0.015375 109.1639927
0.0665699 0.015375 110.6726532
0.0670699 0.015375 112.2268162
0.0675699 0.015375 113.8234023
0.0680699 0.015375 115.459194
0.0685699 0.015375 117.1308547
0.0690699 0.015375 118.8349475
0.0695699 0.015375 120.5679527
0.0700699 0.015375 122.3262849
0.0705699 0.015375 124.1063092
0.0710699 0.015375 125.9043566
0.0715699 0.015375 127.7167387
0.0720699 0.015375 129.5397621
0.0725699 0.015375 131.3697412
0.0730699 0.015375 133.2030114
0.0735699 0.015375 135.0359408
0.0740699 0.015375 136.8649415
0.0745699 0.015375 138.6864806
0.0750699 0.015375 140.4970898
0.0755699 0.015375 142.2933753
0.0760699 0.015375 144.0720262
0.0765699 0.015375 145.8298229
0.0770699 0.015375 147.5636449
0.0775699 0.015375 149.2704775
0.0780699 0.015375 150.9474186
0.0785699 0.015375 152.5916844
0.0790699 0.015375 154.2006151
0.0795699 0.015375 155.7716795
0.0800699 0.015375 157.3024795
0.0805699 0.015375 158.790754
0.0810699 0.015375 160.2343822
0.0815699 0.015375 161.6313866
0.0820699 0.015375 162.9799354
0.0825699 0.015375 164.2783442
0.0830699 0.015375 165.5250783
0.0835699 0.015375 166.7187531
0.0840699 0.015375 167.858135
0.0845699 0.015375 168.9421419
0.0850699 0.015375 169.9698431
0.0855699 0.015375 170.9404585
0.0860699 0.015375 171.8533582
0.0865699 0.015375 172.7080612
0.0870699 0.015375 173.5042336
0.0875699 0.015375 174.2416873
0.0880699 0.015375 174.9203774
0.0885699 0.015375 175.5403999
0.0890699 0.015375 176.1019887
0.0895699 0.015375 176.6055133
0.0900699 0.015375 177.0514745
0.0905699 0.015375 177.4405016
0.0910699 0.015375 177.7733483
0.0915699 0.015375 178.0508888
0.0920699 0.015375 178.2741135
0.0925699 0.015375 178.4441243
0.0930699 0.015375 178.5621305
0.0935699 0.015375 178.6294436
0.0940699 0.015375 178.6474724
0.0945699 0.015375 178.6177179
0.0950699 0.015375 178.5417678
0.0955699 0.015375 178.4212916
0.0960699 0.015375 178.2580344
0.0965699 0.015375 178.0538118
0.0970699 0.015375 177.810504
0.0975699 0.015375 177.5300496
0.0980699 0.015375 177.2144405
0.0985699 0.015375 176.8657153
0.0990699 0.015375 176.4859534
0.0995699 0.015375 176.0772692
0.1000699 0.015375 175.6418062
0.1005699 0.015375 175.1817303
0.1010699 0.015375 174.6992244
0.1015699 0.015375 174.1964822
0.1020699 0.015375 173.675702
0.1025699 0.015375 173.1390809
0.1030699 0.015375 172.5888089
0.1035699 0.015375 172.027063
0.1040699 0.015375 171.4560017
0.1045699 0.015375 170.8777588
0.1050699 0.015375 170.2944383
0.1055699 0.015375 169.7081088
0.1060699 0.015375 169.1207982
0.1065699 0.015375 168.5344883
0.1070699 0.015375 167.9511102
0.1075699 0.015375 167.372539
0.1080699 0.015375 166.8005894
0.1085699 0.015375 166.2370111
0.1090699 0.015375 165.6834844
0.1095699 0.015375 165.1416163
0.1100699 0.015375 164.6129364
0.1105699 0.015375 164.0988936
0.1110699 0.015375 163.6008524
0.1115699 0.015375 163.1200901
0.1120699 0.015375 162.6577937
0.1125699 0.015375 162.2150575
0.1130699 0.015375 161.7928806
0.1135699 0.015375 161.3921656
0.1140699 0.015375 161.0137162
0.1145699 0.015375 160.6582364
0.1150699 0.015375 160.3263295
0.1155699 0.015375 160.0184976
0.1160699 0.015375 159.735141
0.1165699 0.015375 159.4765591
0.1170699 0.015375 159.2429503
0.1175699 0.015375 159.0344135
0.1180699 0.015375 158.8509493
0.1185699 0.015375 158.6924617
0.1190699 0.015375 158.558761
0.1195699 0.015375 158.4495657
0.1200699 0.015375 158.3645068
0.1205699 0.015375 158.3031304
0.1210699 0.015375 158.2649028
0.1215699 0.015375 158.2492148
0.1220699 0.015375 158.2553872
0.1225699 0.015375 158.2826761
0.1230699 0.015375 158.3302801
0.1235699 0.015375 158.3973462
0.1240699 0.015375 158.4829779
0.1245699 0.015375 158.5862433
0.1250699 0.015375 158.7061833
0.1255699 0.015375 158.841821
0.1260699 0.015375 158.9921719
0.1265699 0.015375 159.156254
0.1270699 0.015375 159.3330989
0.1275699 0.015375 159.5217642
0.1280699 0.015375 159.7213453
0.1285699 0.015375 159.9309888
0.1290699 0.015375 160.1499064
0.1295699 0.015375 160.3773894
0.1300699 0.015375 160.6128241
0.1305699 0.015375 160.8557075
0.1310699 0.015375 161.1056643
0.1315699 0.015375 161.3624643
0.1320699 0.015375 161.6260408
0.1325699 0.015375 161.8965093
0.1330699 0.015375 162.1741879
0.1335699 0.015375 162.4596173
0.1340699 0.015375 162.7535828
0.1345699 0.015375 163.0571361
0.1350699 0.015375 163.3716191
0.1355699 0.015375 163.698687
0.1360699 0.015375 164.0403341
0.1365699 0.015375 164.3989187
0.1370699 0.015375 164.7771902
0.1375699 0.015375 165.1783166
0.1380699 0.015375 165.6059126
0.1385699 0.015375 166.0640694
0.1390699 0.015375 166.5573848
0.1395699 0.015375 167.0909942
0.1400699 0.015375 167.6706035
0.1405699 0.015375 168.3025216
0.1410699 0.015375 168.9936948
0.1415699 0.015375 169.7517423
0.1420699 0.015375 170.584992
0.1425699 0.015375 171.5025179
0.1430699 0.015375 172.5141784
0.1435699 0.015375 173.6306555
0.1440699 0.015375 174.8634954
0.1445699 0.015375 176.2251495
0.1450699 0.015375 177.7290177
0.1455699 0.015375 179.3894911
0.1460699 0.015375 181.2219976
0.1465699 0.015375 183.2430474
0.1470699 0.015375 185.4702797
0.1475699 0.015375 187.9225117
0.1480699 0.015375 190.6197872
0.1485699 0.015375 193.5834271
0.1490699 0.015375 196.8360819
0.1495699 0.015375 200.4017834
0.1500699 0.015375 204.3059998
0.1505699 0.015375 208.5756905
0.1510699 0.015375 213.2393628
0.1515699 0.015375 218.3271296
0.1520699 0.015375 223.8707687
0.1525699 0.015375 229.9037829
0.1530699 0.015375 236.4614616
0.1535699 0.015375 243.580944
0.0431782 0.017375 80.64599005
0.0436782 0.017375 81.56249763
0.0441782 0.017375 82.34194793
0.0446782 0.017375 83.00074446
0.0451782 0.017375 83.55433555
0.0456782 0.017375 84.01724695
0.0461782 0.017375 84.40311369
0.0466782 0.017375 84.72471138
0.0471782 0.017375 84.99398684
0.0476782 0.017375 85.22208812
0.0481782 0.017375 85.41939391
0.0486782 0.017375 85.59554233
0.0491782 0.017375 85.75945909
0.0496782 0.017375 85.91938509
0.0501782 0.017375 86.0829034
0.0506782 0.017375 86.25696566
0.0511782 0.017375 86.44791786
0.0516782 0.017375 86.66152564
0.0521782 0.017375 86.90299888
0.0526782 0.017375 87.17701585
0.0531782 0.017375 87.4877467
0.0536782 0.017375 87.83887648
0.0541782 0.017375 88.23362756
0.0546782 0.017375 88.6747815
0.0551782 0.017375 89.16470041
0.0556782 0.017375 89.70534777
0.0561782 0.017375 90.29830876
0.0566782 0.017375 90.94480995
0.0571782 0.017375 91.64573865
0.0576782 0.017375 92.4016616
0.0581782 0.017375 93.21284324
0.0586782 0.017375 94.07926345
0.0591782 0.017375 95.00063484
0.0596782 0.017375 95.97641948
0.0601782 0.017375 97.00584525
0.0606782 0.017375 98.08792159
0.0611782 0.017375 99.22145494
0.0616782 0.017375 100.4050635
0.0621782 0.017375 101.6371919
0.0626782 0.017375 102.916125
0.0631782 0.017375 104.2400012
0.0636782 0.017375 105.6068262
0.0641782 0.017375 107.014485
0.0646782 0.017375 108.4607546
0.0651782 0.017375 109.9433155
0.0656782 0.017375 111.4597633
0.0661782 0.017375 113.0076196
0.0666782 0.017375 114.5843425
0.0671782 0.017375 116.1873373
0.0676782 0.017375 117.8139653
0.0681782 0.017375 119.4615545
0.0686782 0.017375 121.1274073
0.0691782 0.017375 122.8088102
0.0696782 0.017375 124.5030416
0.0701782 0.017375 126.2073798
0.0706782 0.017375 127.9191104
0.0711782 0.017375 129.6355339
0.0716782 0.017375 131.3539723
0.0721782 0.017375 133.0717755
0.0726782 0.017375 134.7863279
0.0731782 0.017375 136.4950537
0.0736782 0.017375 138.1954231
0.0741782 0.017375 139.8849568
0.0746782 0.017375 141.5612315
0.0751782 0.017375 143.2218843
0.0756782 0.017375 144.8646169
0.0761782 0.017375 146.4871996
0.0766782 0.017375 148.0874752
0.0771782 0.017375 149.6633624
0.0776782 0.017375 151.2128587
0.0781782 0.017375 152.7340435
0.0786782 0.017375 154.225081
0.0791782 0.017375 155.6842219
0.0796782 0.017375 157.109806
0.0801782 0.017375 158.5002641
0.0806782 0.017375 159.8541191
0.0811782 0.017375 161.1699881
0.0816782 0.017375 162.4465829
0.0821782 0.017375 163.6827114
0.0826782 0.017375 164.8772779
0.0831782 0.017375 166.0292841
0.0836782 0.017375 167.1378289
0.0841782 0.017375 168.2021087
0.0846782 0.017375 169.2214173
0.0851782 0.017375 170.1951456
0.0856782 0.017375 171.122781
0.0861782 0.017375 172.0039068
0.0866782 0.017375 172.8382015
0.0871782 0.017375 173.6254377
0.0876782 0.017375 174.3654806
0.0881782 0.017375 175.0582873
0.0886782 0.017375 175.7039051
0.0891782 0.017375 176.3024693
0.0896782 0.017375 176.8542026
0.0901782 0.017375 177.359412
0.0906782 0.017375 177.8184877
0.0911782 0.017375 178.2319005
0.0916782 0.017375 178.6001996
0.0921782 0.017375 178.9240106
0.0926782 0.017375 179.2040324
0.0931782 0.017375 179.4410352
0.0936782 0.017375 179.6358576
0.0941782 0.017375 179.789404
0.0946782 0.017375 179.9026416
0.0951782 0.017375 179.9765976
0.0956782 0.017375 180.0123564
0.0961782 0.017375 180.0110562
0.0966782 0.017375 179.9738864
0.0971782 0.017375 179.902084
0.0976782 0.017375 179.7969308
0.0981782 0.017375 179.6597501
0.0986782 0.017375 179.4919031
0.0991782 0.017375 179.2947862
0.0996782 0.017375 179.0698273
0.1001782 0.017375 178.8184826
0.1006782 0.017375 178.5422332
0.1011782 0.017375 178.242582
0.1016782 0.017375 177.92105
0.1021782 0.017375 177.5791734
0.1026782 0.017375 177.2184998
0.1031782 0.017375 176.8405855
0.1036782 0.017375 176.4469917
0.1041782 0.017375 176.0392815
0.1046782 0.017375 175.6190168
0.1051782 0.017375 175.1877546
0.1056782 0.017375 174.7470449
0.1061782 0.017375 174.2984265
0.1066782 0.017375 173.8434247
0.1071782 0.017375 173.3835483
0.1076782 0.017375 172.9202864
0.1081782 0.017375 172.455106
0.1086782 0.017375 171.989449
0.1091782 0.017375 171.5247297
0.1096782 0.017375 171.0623322
0.1101782 0.017375 170.6036081
0.1106782 0.017375 170.1498741
0.1111782 0.017375 169.7024097
0.1116782 0.017375 169.2624552
0.1121782 0.017375 168.8312097
0.1126782 0.017375 168.4098293
0.1131782 0.017375 167.9994253
0.1136782 0.017375 167.6010627
0.1141782 0.017375 167.2157587
0.1146782 0.017375 166.8444814
0.1151782 0.017375 166.4881487
0.1156782 0.017375 166.1476276
0.1161782 0.017375 165.823733
0.1166782 0.017375 165.5172272
0.1171782 0.017375 165.2288198
0.1176782 0.017375 164.9591669
0.1181782 0.017375 164.7088715
0.1186782 0.017375 164.4784834
0.1191782 0.017375 164.2684997
0.1196782 0.017375 164.079365
0.1201782 0.017375 163.9114728
0.1206782 0.017375 163.7651658
0.1211782 0.017375 163.6407377
0.1216782 0.017375 163.5384341
0.1221782 0.017375 163.4584547
0.1226782 0.017375 163.4009548
0.1231782 0.017375 163.3660479
0.1236782 0.017375 163.3538077
0.1241782 0.017375 163.3642712
0.1246782 0.017375 163.3974411
0.1251782 0.017375 163.4532898
0.1256782 0.017375 163.5317624
0.1261782 0.017375 163.6327804
0.1266782 0.017375 163.7562463
0.1271782 0.017375 163.9020474
0.1276782 0.017375 164.070061
0.1281782 0.017375 164.260159
0.1286782 0.017375 164.4722135
0.1291782 0.017375 164.7061022
0.1296782 0.017375 164.9617144
0.1301782 0.017375 165.2389574
0.1306782 0.017375 165.5377631
0.1311782 0.017375 165.8580948
0.1316782 0.017375 166.1999546
0.1321782 0.017375 166.5633911
0.1326782 0.017375 166.9485075
0.1331782 0.017375 167.3554696
0.1336782 0.017375 167.7845151
0.1341782 0.017375 168.2359624
0.1346782 0.017375 168.7102202
0.1351782 0.017375 169.2077973
0.1356782 0.017375 169.729313
0.1361782 0.017375 170.275508
0.1366782 0.017375 170.847255
0.1371782 0.017375 171.4455708
0.1376782 0.017375 172.0716278
0.1381782 0.017375 172.7267664
0.1386782 0.017375 173.4125082
0.1391782 0.017375 174.1305687
0.1396782 0.017375 174.8828712
0.1401782 0.017375 175.671561
0.1406782 0.017375 176.4990198
0.1411782 0.017375 177.3678807
0.1416782 0.017375 178.2810439
0.1421782 0.017375 179.2416924
0.1426782 0.017375 180.2533087
0.1431782 0.017375 181.3196913
0.1436782 0.017375 182.4449726
0.1441782 0.017375 183.6336363
0.1446782 0.017375 184.8905363
0.1451782 0.017375 186.220915
0.1456782 0.017375 187.6304233
0.1461782 0.017375 189.12514
0.1466782 0.017375 190.7115927
0.1471782 0.017375 192.3967784
0.1476782 0.017375 194.1881852
0.1481782 0.017375 196.0938141
0.1486782 0.017375 198.1222021
0.1491782 0.017375 200.2824447
0.1496782 0.017375 202.58422
0.1501782 0.017375 205.0378128
0.1506782 0.017375 207.6541397
0.1511782 0.017375 210.4447738
0.1516782 0.017375 213.4219715
0.1521782 0.017375 216.5986986
0.1526782 0.017375 219.9886574
0.1531782 0.017375 223.6063148
0.1536782 0.017375 227.4669303
0.1541782 0.017375 231.5865852
0.1546782 0.017375 235.9822118
0.1551782 0.017375 240.6716242
0.1556782 0.017375 245.6735485
0.1561782 0.017375 251.0076548
0.1566782 0.017375 256.6945888
答案 0 :(得分:0)
data.table解决方案可能更优雅,但应该完成工作。
library(data.table)
## setDT() necessary if a and b are standard R data.frame objects
setDT(a)
setDT(b)
## Make a range summary table for a, grouped by Y, and set the key, Y
a_range <- a[,.(min_X_a = min(X),
max_X_a = max(X)), keyby = .(Y)]
## Set key for b as Y
setkey(b,Y)
## Join the two tables, subset where the range conditions are met,
## and delete the min/max summary columns
c <- b[a_range][X > min_X_a
& X < max_X_a][,c("min_X_a","max_X_a") := NULL]
请编辑下面的代码,以便它提供两个data.frames及其预期输出的简化样本集。这将允许其他人帮助解决您的问题,而无需花时间将示例数据纠缠到R可读的内容中。
# Set 'a'
a <- data.frame(X = c(1,2,3,1,2),
Y = c(1,1,1,2,2),
res = c(1,2,3,4,5))
# Set 'b'
b <- data.frame(X = c(0.5, 1.0, 2.5, 2.0, 3.5),
Y = c(1,1,1,2,2),
res = c(6,7,8,9,10))
## Expected Result
c <- data.frame(X = c(1.0,2.5,2.0),
Y = c(1,1,2),
res = c(7,8,9))