按间隔对数据 table 值进行分组

Grouping data table values in intervals

我有一个数据 table dt.data 超过 7000000 行,看起来像这个数据片段:

dt.data <- structure(list(nbVerbrauch = c(621, 1143300, 10335, 7521, 5632, 
5000, 15283, 40454, 16289, 5933, 24281, 50413, 20000, 11823, 
10952, 50236, 38842, 29590, 15000, 32804, 23721, 19803, 818, 
20368, 25433, 28330, 24837, 28093, 20345, 380367, 25379, 30292, 
14840, 15000, 319, 10000, 638, 40000, 7000, 3779, 3000, 9751, 
11822, 5000, 500, 4336, 6820, 31998, 13000, 11182, 1208, 10767, 
7661, 14806, 37892, 6979, 21895, 5000, 21023, 5000, 25714, 74892, 
72273, 14147, 1500, 2000, 2000, 200, 20000, 1500, 3000, 8585, 
16224, 1500, 1324, 1800, 2000, 1500, 3398, 3500, 1000, 2500, 
1500, 2500, 1800, 1700, 1290, 1500, 200, 2049, 2033, 5500, 3500, 
3500, 2100, 3500, 3066, 1365, 7650, 14700, 36364, 18360, 6639, 
5114, 151369, 15143, 9295, 4453, 87387, 27341, 21501, 500, 17529, 
14699, 13315, 17918, 1001, 28371, 10999, 20788, 12000, 97933, 
10420, 9352, 25599, 2000, 19998, 8737, 17347, 14148, 33574, 34277, 
22450, 14017, 17740, 12708, 37326, 3200, 25912, 77952, 20000, 
4000, 10001934, 7000, 6000, 260, 10000, 7146, 13087, 9189, 1000, 
5500, 10904, 8689, 37246, 62483, 8289, 10413, 788, 30077, 9323, 
10495, 226581, 68548, 276825, 7000, 4546, 19897, 6255, 12858, 
15000, 14750, 100, 4000, 2000, 5268, 2500, 4800, 2000, 721, 2100, 
200, 100, 120, 2249, 2761, 9203, 2000, 2874, 1500, 486, 3500, 
4000, 14780, 2200, 3000, 1358, 5000, 1232, 3783, 20595, 1500, 
36429, 80, 43407, 39068, 15000, 36771, 27553, 45633, 22879, 33000, 
27488, 40000, 21718, 16688, 19020, 139069, 12188, 6000, 17693, 
7894, 8000, 21117, 9000, 20037, 12000, 23143, 5889, 8236, 22774, 
9000, 81463, 31010, 2358, 100, 3048, 100, 4000, 7000, 1586, 100, 
5000, 5804, 19040, 14336, 1349, 4527, 37355, 12000, 11774, 17807, 
18000, 5072, 8824, 10000, 12788, 16000, 150000, 65759, 7258, 
267960, 5076, 2000, 67778, 4000, 13843, 11540, 700, 7831, 10149, 
889, 1200, 5000, 2000, 3500, 2800, 3000, 23787, 4500, 1276, 248, 
3500, 2500, 3000, 1500, 2843, 10000, 2000, 4000, 2500, 1500, 
19215, 3000, 273900, 273536, 111042, 31942, 111448, 23981, 16677, 
80000, 32000, 27381, 96870, 4360, 5000, 32101, 10331, 13750, 
5000, 10000, 19093, 142487, 831, 6000, 20726, 29000, 24825, 2000, 
29337, 164982, 4180, 18112, 13132, 32176, 29000, 21833, 14139, 
1505, 19382, 26330, 26214, 20034, 31215, 5784, 1000, 15000, 34841, 
8000, 11810, 12548, 10835, 4500, 13287, 13368, 8000, 20000, 12938, 
4094, 1599, 17382, 19568, 500, 2400, 118138, 14000, 12919, 9975, 
9553, 6090, 76616, 12000, 20873, 67237, 74463, 10416, 4000, 2000, 
3671, 1000, 3000, 1500, 30687, 15000, 3283, 1500, 100, 2000, 
3000, 3500, 1291, 2800, 1584, 1995, 5400, 1400, 2000, 6092, 1376, 
4794, 2047, 5806, 2500, 4000, 10046, 3000, 802, 201162, 550000, 
71924, 45261, 33029, 4000, 6567, 20000, 30876, 28938, 33212, 
49440, 31610, 31660, 33320, 2000, 2271, 89110, 21512, 3771, 28899, 
3056, 45000, 20851, 4639, 9607, 51129, 43000, 11087, 21000, 19232, 
28914, 6500, 35000, 21680, 22434, 10316, 1000, 6900, 19201, 15000, 
24619, 15604, 6910, 12963, 1439, 26620, 37768, 13910, 32, 9000, 
14000, 19574, 18721, 30000, 1500, 3500, 2947, 1500, 1690, 2800, 
3000, 4418, 3000, 2128, 2000, 60, 1500, 1676, 1700, 5000, 300, 
200, 2000, 100, 2827, 4261, 6000, 3000, 2538, 2500, 1888, 4742, 
3000, 1900, 2000, 2368, 3642, 3300, 2000, 1500, 2000, 3200, 2420, 
3310, 1500, 1023, 3000, 6300, 16526, 500, 1521, 5992, 394, 948, 
1034, 19234, 2500, 34919, 4000, 3500, 4000, 802, 2000, 2000, 
48220, 36000, 1008, 1200, 4993, 1500, 11541, 2015, 1564, 2500, 
1976, 7822, 3500, 1, 2000, 350, 15114, 931, 1200, 2500, 1500, 
733, 900, 3537, 3500, 2000, 433, 2500, 15070, 4500, 238, 1912, 
4664, 10000, 3141, 1675, 5080, 3500, 2000, 1000, 2500, 1300, 
6505, 18523, 1500, 819, 1800, 2630, 1600, 500, 2500, 3000, 3500, 
22702, 1457, 2407, 2000, 1500, 1500, 2892, 1399, 1500, 2031, 
4000, 4169, 4200, 20408, 4500, 1502, 13487, 2788, 9927, 2500, 
1600, 5457, 4902, 4433, 700, 799, 3600, 300, 97050, 306, 3237, 
71505342, 148501, 40493, 20234, 14979, 33802, 45223, 25663, 19625, 
8000, 3346, 11966, 15000, 33743, 9903, 24193, 20273, 118625, 
63086, 60000, 8137, 34522, 18413, 37752, 12070, 12000, 32448, 
38556, 22146, 20708, 4564, 15773, 17564, 28272, 19498, 18536, 
21075, 18570, 30656, 5991, 17351, 10126, 3989, 100, 8000, 5533, 
1000, 21944, 1, 25482, 8000, 14097, 38527, 10763, 15351, 6564, 
5000, 11508, 5165, 19000, 102, 340770, 17174, 14323, 4531, 68995, 
1500, 2500, 1976, 1500, 1500, 1000, 200, 1000, 1600, 3500, 8000, 
3500, 348, 9737, 3694, 3792, 14289, 1727, 2000, 3000, 11, 2117, 
3500, 344616, 7161, 7835, 25000, 28225, 29631, 19133, 1800, 61546, 
31020, 36184, 27308, 5000, 20000, 8393, 24572, 7932, 11328, 7615, 
59497, 10471, 26110, 18340, 36578, 32039, 9406, 9279, 15000, 
20980, 15829, 20000, 17000, 5967, 4000, 17177, 8484, 12747, 10000, 
9994, 18850, 22616, 10000, 6000, 4700, 15000, 8000, 16117, 6893, 
10000, 11163, 11000, 11404, 1861, 25115, 41939, 827, 48370, 3490, 
6330028, 115950, 1200, 1050, 3500, 2500, 2500, 3500, 6000, 4000, 
3500, 1595, 1025, 3000, 3500, 15396, 9103, 1300, 4800, 2200, 
2093, 2700, 1500, 2000, 1059, 2500, 2800, 40000, 2000, 4767, 
2500, 4966, 3802, 2000, 32000, 2500, 100, 5585, 474996, 32707, 
68759, 14473, 3366, 22109, 8045, 33127, 5079, 8116, 20000, 5000, 
5000, 5303, 14458, 35400, 29311, 12000, 6000, 5406, 9669, 3000, 
27722, 55866, 8377, 18242, 14336, 11510, 33857, 7535, 17000, 
14000, 5025, 7450, 17000, 13590, 3000, 15000, 21909, 2000, 100, 
49148, 24310, 12000, 3000, 9233, 3452, 23588, 6986, 31249, 13013, 
114916, 2013, 21000, 22713, 35111, 4350, 2000, 4000, 2000, 2249, 
4000, 2158, 700, 3075, 1703, 2000, 3072, 35875, 3000, 5000, 70, 
5605, 5177, 2600, 6500, 3223, 200, 4809, 6000, 2000, 1800, 1000, 
15370, 2000, 6000, 3500, 2000, 1000, 100, 1199, 900, 2500, 4200, 
1514, 1500, 1641, 16000, 5978, 10277, 1500, 2500, 500, 2000, 
4000, 500, 2143, 100, 3865, 1376, 8727, 2334, 7010, 2000, 3000, 
1639, 4500, 1500, 3000, 3116, 4000, 1662, 11804, 100, 902, 200, 
1823, 3600, 18000, 21471, 1095, 4200, 1500, 2000, 1500, 3900, 
1873, 13596, 2346, 21887, 2532, 1848, 1200, 19137, 6000, 224, 
599, 2500, 11877, 2807, 2000, 2170, 7199, 1284, 400, 2500, 1507, 
4082, 2000, 12657, 1100, 12346, 3200, 1000, 2017, 2500, 8114, 
4532, 8000, 2384, 1500, 2500, 4000, 2000, 1835, 14457, 1500, 
1752, 5116, 100, 2500, 3000, 1000, 2000, 2000, 8862251, 3000, 
1000, 2037, 1500, 3000, 2000, 240221, 3060, 10, 7934, 1000, 888, 
1866, 80000, 9599, 65003, 6808320, 4020000, 185422, 5091, 1341, 
13594, 6500, 36728, 17000, 24356, 31000, 5048, 91805, 42019, 
24258, 29739), hrVerbrauch = c(809.7, 84105, 11319.2, 7283.4, 
6474.1, 1800.8, 7996.5, 42267.4, 17605.5, 10563, 14658.5, 14526.3, 
24088.2, 12734.5, 8722.1, 40063.2, 36757.2, 25742.2, 10870.4, 
31417.4, 23111.3, 22219.9, 28796, 24333.8, 4622, 9319.3, 16706.8, 
28704.3, 16405, 79422.9, 11782.4, 699.4, 6206.2, 5495.9, 16266, 
6057.9, 9372.9, 8271.3, 10020.5, 10172, 15757.7, 26833.5, 13973, 
38010.6, 1720.2, 2202, 5514.7, 23177.2, 14396, 14042.2, 1924.5, 
3475.5, 8374.5, 8741, 37997.3, 5990.9, 16257.5, 5114, 2608.8, 
33887.1, 17579.8, 17127.1, 13291, 1978.9, 8280.46, 2377.4, 1156.78, 
2268.6, 53.1, 761.91, 509.1, 2771.32, 4229.8, 929.3, 581.46, 
1528.51, 2122.88, 468.55, 3763.38, 355.13, 4.9, 1361.23, 1289.1, 
2298.69, 3618.98, 1121.15, 705.8, 709.32, 2470.28, 2617.2, 495.89, 
2508.44, 556.39, 425.4, 0, 3449.8, 211.11, 736.2, 741.7, 13370.3, 
226.7, 4064.4, 8737.01, 36.7, 116523.8, 17051.1, 13442.7, 8330.5, 
29325, 16017.9, 19352, 5083.6, 57975.6, 9758.4, 11885.8, 14687.9, 
12833.8, 0, 887.3, 22434.6, 10138.4, 158441.6, 3529.1, 3057.5, 
25416.4, 16967.6, 326.1, 10520.9, 20860.4, 9118.7, 21708.6, 29523, 
5124.8, 31507.4, 1753, 0, 27041.4, 15289.4, 21743.6, 126955.6, 
0, 17294.3, 511043, 10027.8, 11076.7, 0, 82.8, 4701.6, 16516.8, 
7407.4, 1032.9, 959.8, 877.9, 10220.2, 9205.2, 62765.9, 724.1, 
4645.8, 1289.8, 29706.3, 8462, 13812.8, 263.9, 48690.3, 1224.2, 
10386.9, 4198, 24721, 2394.4, 11019.2, 11630.3, 1861.4, 191.6, 
1420.26, 603.7, 2091.37, 703.27, 4805.7, 961.71, 457.32, 2297.4, 
1018.13, 8.4, 429.88, 242.9, 3537.68, 5145.44, 1182.7, 3304.57, 
182.75, 0, 6988.75, 4674.52, 15059.4, 5351.34, 0, 1.98, 2411.66, 
4723.3, 775.68, 10920.3, 882.95, 31982.2, 10005.55, 27017.1, 
0, 89031.9, 34438.3, 29945.5, 8216.7, 30195.8, 20407.1, 33093.7, 
28116.4, 21256.2, 2096.3, 21454.1, 125616.2, 13728.5, 11463.6, 
15501.9, 8844.6, 6278.9, 31510.3, 10.8, 16393.6, 12945.2, 3474.2, 
0, 1981.9, 15903, 13128.3, 6294.8, 224.2, 12123.7, 0, 2830.4, 
0, 3523.3, 6723.7, 6517.1, 5449.9, 10715.1, 7433.7, 10438.4, 
3070.3, 3449.4, 78.7, 35344.9, 5532.4, 2795.6, 18856, 0, 58.8, 
8837.5, 19232.9, 15179.7, 5588.8, 601.8, 42290.3, 8459.1, 11540.6, 
10082.4, 120.69, 89396.4, 5001.9, 15544.1, 60.1, 248.3, 5120.7, 
6227.8, 93.9, 1086.4, 1998.38, 2656.07, 1688.4, 1591.74, 1958.6, 
16296.6, 3089.5, 822.03, 10246.8, 329, 197.5, 100.2, 67.13, 684.45, 
8120.26, 82.91, 3591.52, 11.76, 519.01, 20184.4, 1354.47, 17123.2, 
27392.5, 13485.8, 8175.3, 111232.9, 23770, 10685, 128930.3, 35154.5, 
32480.2, 181548.4, 2875.1, 25033.5, 2297.7, 11719.7, 8049.5, 
42803.3, 0, 33262.1, 6368.5, 28.1, 457.8, 18003.6, 36623.2, 17805.8, 
21429, 27715.6, 0, 1411.1, 21534.1, 7842, 121.1, 24847.5, 2260.4, 
5466.2, 17136.3, 12669.8, 26100.4, 26360.7, 13379.1, 19792.9, 
10244.7, 19816.6, 15893.7, 49800.6, 5054.6, 3299.1, 18294.5, 
318.8, 17699.5, 16603.7, 1813.6, 23996.4, 3057.5, 13453, 2269.6, 
7406.1, 0, 18253.1, 16920, 9524.5, 105740.9, 20950.1, 2855.9, 
7271.9, 0, 9943.5, 107656.5, 10674.6, 25439.6, 91745.9, 5134.8, 
10532.9, 9712.3, 766.76, 1492.14, 1523.99, 5528.1, 0, 11051.4, 
7358.3, 1021.8, 1564.09, 2616.2, 467.83, 803.8, 3010.59, 1888.9, 
1206.07, 464.1, 1688.8, 16249, 393.96, 858.8, 3824.56, 143.3, 
1649.09, 509.49, 9454.37, 312.64, 1474.2, 7891.28, 287.4, 1499.2, 
20246.1, 15474.6, 0, 13439.4, 25192.1, 3957.8, 37740, 16608, 
37279.5, 21960, 36247.5, 37884.9, 642, 33511.4, 23129.4, 21256, 
3609.5, 29528.3, 3216.3, 5856.8, 37483.3, 27584.9, 23255.2, 2281.1, 
18448.9, 8178.6, 60711.4, 21313, 17057.2, 13034.8, 19837, 4502.9, 
3070.1, 24457.4, 25144.3, 3431.3, 1.5, 20960.3, 9810.8, 14729.6, 
13624.6, 11024.8, 16884.6, 7156.5, 0, 1.5, 16586.2, 34585.7, 
13848, 29894.5, 10289.4, 19298.3, 24866, 5119.4, 41436.6, 436.04, 
1953.6, 708.49, 403.18, 2479, 1924.3, 1995.87, 4616.06, 1066.71, 
1411.6, 444.09, 190.57, 577.82, 1694.87, 3906.1, 13.24, 979.5, 
7.1, 51.99, 2271.7, 3122.16, 4265.61, 337.16, 1242.8, 2779.83, 
4528.41, 648.71, 5317.28, 515.55, 761.5, 668.2, 2414.16, 3366.46, 
2453.5, 1295.15, 1046.2, 1260.3, 946.67, 16.56, 1586.1, 2113.23, 
234.93, 829.17, 3292.6, 168.9, 5336.5, 5.1, 1113.2, 4667.1, 3681.5, 
545.9, 16480.5, 1316.6, 29584.2, 1611.75, 3384.2, 1739.71, 25.6, 
1601.87, 0, 9551.6, 3634.2, 2796.8, 2178.69, 3613, 667.98, 17846.3, 
579.5, 1158.12, 2270.2, 1974.2, 6201.7, 958.6, 823.7, 1545.05, 
832.94, 20572.61, 361.79, 995.46, 379.89, 1149.35, 279.6, 191.2, 
3874, 3535.09, 775.3, 314.73, 2368.97, 14152.2, 32.9, 322.2, 
3590.33, 5395.9, 2749.3, 282.1, 1627.63, 2138.4, 594.6, 1126.58, 
348.14, 73.97, 499.1, 12172.86, 16617.2, 945.42, 692.06, 195.75, 
429.9, 865.82, 117.58, 0, 2363.7, 3764.85, 10676.1, 129, 1314.7, 
1457.7, 405.95, 47.5, 400.7, 2804, 1836.45, 500.1, 640.09, 3396.1, 
160.4, 18611.1, 3187.43, 1970.1, 10424.19, 2722.9, 6337.8, 969.8, 
1433.9, 5694.07, 3769.1, 3717.45, 908.42, 1418.76, 554.2, 0, 
66441.8, 189.4, 6476.3, 348097.6, 0, 35102.1, 81365.8, 20251.6, 
21396.2, 33860.3, 20485.3, 21377.1, 0, 19106.8, 1816.7, 22794.8, 
7236.9, 13156, 27981.9, 11923, 35445.7, 65973.6, 45523.6, 7648.3, 
40595.9, 15855.2, 43130.7, 0, 18260.6, 24332.5, 3347.7, 21219.4, 
29576, 2701.6, 7638.3, 20779.7, 15387.8, 1506.9, 15926.7, 22869.7, 
19897.5, 27987.1, 2530.9, 17228.7, 13888.6, 4067.7, 5333.5, 3860, 
9156.8, 1006.9, 90.3, 4850.4, 26271.4, 3003.8, 3510, 36981.8, 
9344.5, 9367.3, 0, 4933.7, 601.5, 1438.2, 19662.7, 51.5, 356.4, 
0, 5265.5, 3861.4, 83794.7, 785.7, 436.74, 390.4, 369.12, 2891.95, 
3482.6, 4223.62, 135.8, 1649.5, 5475.88, 1237.86, 8502.37, 6.4, 
1802.8, 3742.1, 1022.72, 9888.6, 941.35, 49.9, 0, 0, 768.6, 1398.8, 
57486.7, 8642.4, 21886.7, 16414.1, 26819.6, 39614.9, 9790.3, 
6978.1, 52052.9, 28258.7, 47276.3, 6809.1, 0, 5108.1, 2407.5, 
12377, 6507.8, 371, 4.7, 590.8, 1703.4, 15308.7, 19309.2, 4803.6, 
26848.9, 14503.7, 3010.2, 7770.9, 11536.2, 19327.2, 4817.8, 19676.8, 
0, 5541.1, 13231.8, 8322.5, 3327.6, 16746, 9587, 22282.3, 15990.4, 
1842.5, 5720, 8157.2, 1033.1, 373.2, 8999.9, 5801.8, 3727.1, 
448.2, 1784.8, 1285.2, 1868.5, 25186.7, 4435.2, 195, 18450.1, 
6960.6, 292908.1, 75548.2, 1180.6, 577.68, 410.15, 287.27, 316.48, 
439.7, 3116.29, 991.8, 477.8, 1684.18, 113, 657.58, 12344.5, 
13285.28, 8945.53, 3131.1, 1293.9, 433.98, 3841.82, 1708.95, 
858.13, 2877.4, 109.9, 1451.75, 1563.1, 29734.8, 746.3, 2344.6, 
1283, 2740.61, 58.05, 337.9, 18099.5, 33.92, 3890.2, 35178.2, 
2814.1, 1290.2, 21254.4, 11330.9, 2659.1, 20346.8, 9834.9, 26541, 
13159.2, 10011.8, 19927.5, 1.6, 9329, 9006.8, 9033.6, 4079.4, 
5132.6, 23198.1, 8988.9, 9712.2, 1916, 1357.5, 3186.2, 89300, 
11899.4, 11847.7, 16966, 13006.3, 6063.8, 11914, 28362.3, 5033, 
5150.6, 350.2, 29514.2, 13401.9, 7294, 369.5, 19992.4, 6994.6, 
30739, 15418.4, 17413.8, 2383.7, 16506.6, 3186, 10264.2, 17592.5, 
5907.8, 20681.3, 13609.7, 10299.7, 361.8, 2004.3, 16124.1, 0, 
13801.5, 633.1, 18121.3, 2091.15, 921.28, 4651.19, 1069.21, 52.5, 
5220.41, 1396.27, 2444.14, 1541.49, 22851.3, 219.6, 1956.3, 580.4, 
4123.6, 3288.2, 3394.9, 1244, 2367.1, 0, 3825.78, 1639.99, 1906.69, 
1.4, 601.8, 245.5, 1254.27, 521.5, 625.95, 7708.03, 21.1, 0, 
1933, 2222.79, 1404.63, 1332.8, 2953.59, 43.4, 3996.17, 897.5, 
7365.4, 15886.1, 1595.32, 577.13, 1543.43, 1545.9, 14070.81, 
1007.1, 1197.3, 137.2, 3651.62, 1088.5, 7238.4, 776, 1662.4, 
811.3, 220.87, 338.77, 750.77, 537.7, 209.18, 993, 204.45, 247.5, 
12248, 229.6, 3437.1, 336.6, 1954.68, 2290.42, 3506.9, 18151.2, 
782, 1327.8, 1250.99, 2053.88, 656.82, 3614.4, 1688.4, 17769.1, 
1511.9, 7582.1, 181.12, 119.83, 1576.71, 17596, 16381.5, 0, 1070.12, 
1685.5, 10794.2, 7652.2, 0, 2409.28, 5408.7, 228.9, 158.71, 1982.63, 
521.83, 3458, 503.18, 25705.32, 622.2, 2527, 2596.3, 1900.85, 
0, 1841.2, 304.3, 746.85, 6045.56, 1361.1, 1151.14, 0, 92.6, 
408.9, 1010.6, 12656.1, 1810.4, 1100.5, 7339.8, 2207.2, 1876.3, 
163.85, 1187.08, 173.44, 1108.29, 0, 69.59, 1995.68, 2509.8, 
227.2, 1935.28, 1604.49, 172509.9, 2666.41, 1958.02, 1314.4, 
284.4, 1448.7, 1025.7, 39362.9, 1105, 35601.6, 336564, 87380, 
3954.6, 440.7, 294.5, 9705.7, 1051.3, 36275.5, 17379.8, 27590.5, 
2828.5, 21835.8, 66841.9, 45138.8, 6820.9, 30505.7), diff = c(-188.7, 
1059195, -984.200000000001, 237.6, -842.1, 3199.2, 7286.5, -1813.4, 
-1316.5, -4630, 9622.5, 35886.7, -4088.2, -911.5, 2229.9, 10172.8, 
2084.8, 3847.8, 4129.6, 1386.6, 609.700000000001, -2416.9, -27978, 
-3965.8, 20811, 19010.7, 8130.2, -611.299999999999, 3940, 300944.1, 
13596.6, 29592.6, 8633.8, 9504.1, -15947, 3942.1, -8734.9, 31728.7, 
-3020.5, -6393, -12757.7, -17082.5, -2151, -33010.6, -1220.2, 
2134, 1305.3, 8820.8, -1396, -2860.2, -716.5, 7291.5, -713.5, 
6065, -105.300000000003, 988.1, 5637.5, -114, 18414.2, -28887.1, 
8134.2, 57764.9, 58982, 12168.1, -6780.46, -377.4, 843.22, -2068.6, 
19946.9, 738.09, 2490.9, 5813.68, 11994.2, 570.7, 742.54, 271.49, 
-122.88, 1031.45, -365.38, 3144.87, 995.1, 1138.77, 210.9, 201.31, 
-1818.98, 578.85, 584.2, 790.68, -2270.28, -568.2, 1537.11, 2991.56, 
2943.61, 3074.6, 2100, 50.1999999999998, 2854.89, 628.8, 6908.3, 
1329.7, 36137.3, 14295.6, -2098.01, 5077.3, 34845.2, -1908.1, 
-4147.7, -3877.5, 58062, 11323.1, 2149, -4583.6, -40446.6, 4940.6, 
1429.2, 3230.1, -11832.8, 28371, 10111.7, -1646.6, 1861.6, -60508.6, 
6890.9, 6294.5, 182.599999999999, -14967.6, 19671.9, -1783.9, 
-3513.4, 5029.3, 11865.4, 4754, 17325.2, -17490.4, 15987, 12708, 
10284.6, -12089.4, 4168.4, -49003.6, 20000, -13294.3, 9490891, 
-3027.8, -5076.7, 260, 9917.2, 2444.4, -3429.8, 1781.6, -32.9000000000001, 
4540.2, 10026.1, -1531.2, 28040.8, -282.900000000001, 7564.9, 
5767.2, -501.8, 370.700000000001, 861, -3317.8, 226317.1, 19857.7, 
275600.8, -3386.9, 348, -4824, 3860.6, 1838.8, 3369.7, 12888.6, 
-91.6, 2579.74, 1396.3, 3176.63, 1796.73, -5.69999999999982, 
1038.29, 263.68, -197.4, -818.13, 91.6, -309.88, 2006.1, -776.68, 
4057.56, 817.3, -430.57, 1317.25, 486, -3488.75, -674.52, -279.4, 
-3151.34, 3000, 1356.02, 2588.34, -3491.3, 3007.32, 9674.7, 617.05, 
4446.8, -9925.55, 16389.9, 39068, -74031.9, 2332.7, -2392.5, 
37416.3, -7316.8, 12592.9, -5605.7, 11883.6, 461.799999999999, 
14591.7, -2434.1, 13452.8, -1540.5, -5463.6, 2191.1, -950.6, 
1721.1, -10393.3, 8989.2, 3643.4, -945.200000000001, 19668.8, 
5889, 6254.1, 6871, -4128.3, 75168.2, 30785.8, -9765.7, 100, 
217.6, 100, 476.7, 276.3, -4931.1, -5349.9, -5715.1, -1629.7, 
8601.6, 11265.7, -2100.4, 4448.3, 2010.1, 6467.6, 8978.4, -1049, 
18000, 5013.2, -13.5, -9232.9, -2391.7, 10411.2, 149398.2, 23468.7, 
-1201.1, 256419.4, -5006.4, 1879.31, -21618.4, -1001.9, -1701.1, 
11479.9, 451.7, 2710.3, 3921.2, 795.1, 113.6, 3001.62, -656.07, 
1811.6, 1208.26, 1041.4, 7490.4, 1410.5, 453.97, -9998.8, 3171, 
2302.5, 2899.8, 1432.87, 2158.55, 1879.74, 1917.09, 408.48, 2488.24, 
980.99, -969.400000000001, 1645.53, 256776.8, 246143.5, 97556.2, 
23766.7, 215.100000000006, 211, 5992, -48930.3, -3154.5, -5099.2, 
-84678.4, 1484.9, -20033.5, 29803.3, -1388.7, 5700.5, -37803.3, 
10000, -14169.1, 136118.5, 802.9, 5542.2, 2722.4, -7623.2, 7019.2, 
-19429, 1621.4, 164982, 2768.9, -3422.1, 5290, 32054.9, 4152.5, 
19572.6, 8672.8, -15631.3, 6712.2, 229.599999999999, -146.700000000001, 
6654.9, 11422.1, -4460.7, -18816.6, -893.700000000001, -14959.6, 
2945.4, 8510.9, -5746.5, 10516.2, -13199.5, -3316.7, 11554.4, 
-15996.4, 16942.5, -515, 1824.4, -5807.1, 17382, 1314.9, -16420, 
-7124.5, 12397.1, -6950.1, 10063.1, 2703.1, 9553, -3853.5, -31040.5, 
1325.4, -4566.6, -24508.9, 69328.2, -116.9, -5712.3, 1233.24, 
2178.86, -523.99, -2528.1, 1500, 19635.6, 7641.7, 2261.2, -64.0899999999999, 
-2516.2, 1532.17, 2196.2, 489.41, -597.9, 1593.93, 1119.9, 306.2, 
-10849, 1006.04, 1141.2, 2267.44, 1232.7, 3144.91, 1537.51, -3648.37, 
2187.36, 2525.8, 2154.72, 2712.6, -697.2, 180915.9, 534525.4, 
71924, 31821.6, 7836.9, 42.1999999999998, -31173, 3392, -6403.5, 
6978, -3035.5, 11555.1, 30968, -1851.4, 10190.6, -19256, -1338.5, 
59581.7, 18295.7, -2085.8, -8584.3, -24528.9, 21744.8, 18569.9, 
-13809.9, 1428.4, -9582.4, 21687, -5970.2, 7965.2, -605, 24411.1, 
3429.9, 10542.6, -3464.3, 19002.7, 10314.5, -19960.3, -2910.8, 
4471.4, 1375.4, 13594.2, -1280.6, -246.5, 12963, 1437.5, 10033.8, 
3182.3, 62, -29862.5, -1289.4, -5298.3, -5292, 13601.6, -11436.6, 
1063.96, 1546.4, 2238.51, 1096.82, -789, 875.7, 1004.13, -198.06, 
1933.29, 716.4, 1555.91, -130.57, 922.18, -18.8699999999999, 
-2206.1, 4986.76, -679.5, 192.9, 1948.01, -2171.7, -295.16, -4.60999999999967, 
5662.84, 1757.2, -241.83, -2028.41, 1239.29, -575.28, 2484.45, 
1138.5, 1331.8, -46.1599999999999, 275.54, 846.5, 704.85, 453.8, 
739.7, 2253.33, 2403.44, 1723.9, -613.23, 788.07, 2170.83, 3007.4, 
16357.1, -4836.5, 1515.9, 4878.8, -4273.1, -2733.5, 488.1, 2753.5, 
1183.4, 5334.8, 2388.25, 115.8, 2260.29, 776.4, 398.13, 2000, 
38668.4, 32365.8, -1788.8, -978.69, 1380, 832.02, -6305.3, 1435.5, 
405.88, 229.8, 1.79999999999995, 1620.3, 2541.4, -822.7, 454.95, 
-482.94, -5458.61, 569.21, 204.54, 2120.11, 350.65, 453.4, 708.8, 
-337, -35.0900000000001, 1224.7, 118.27, 131.03, 917.799999999999, 
4467.1, -84.2, -1678.33, -731.9, 7250.7, 2858.9, 47.3699999999999, 
2941.6, 2905.4, 873.42, 651.86, 2426.03, 800.9, -5667.86, 1905.8, 
554.58, 126.94, 1604.25, 2200.1, 734.18, 382.42, 2500, 636.3, 
-264.85, 12025.9, 1328, 1092.3, 542.3, 1094.05, 1452.5, 2491.3, 
-1405, -336.45, 1530.9, 3359.91, 772.9, 4039.6, 1796.9, 1312.57, 
-468.1, 3062.81, 65.0999999999999, 3589.2, 1530.2, 166.1, -237.07, 
1132.9, 715.55, -208.42, -619.76, 3045.8, 300, 30608.2, 116.6, 
-3239.3, 71157244.4, 148501, 5390.9, -61131.8, -5272.6, 12405.8, 
11362.7, 5177.7, -1752.1, 8000, -15760.8, 10149.3, -7794.8, 26506.1, 
-3253, -3788.9, 8350, 83179.3, -2887.60000000001, 14476.4, 488.7, 
-6073.9, 2557.8, -5378.7, 12070, -6260.6, 8115.5, 35208.3, 926.599999999999, 
-8868, 1862.4, 8134.7, -3215.7, 12884.2, 17991.1, 2609.3, -1794.7, 
-1327.5, 2668.9, 3460.1, 122.299999999999, -3762.6, -78.6999999999998, 
-5233.5, 4140, -3623.8, -6.89999999999998, 21853.7, -4849.4, 
-789.400000000001, 4996.2, 10587, 1545.2, 1418.5, 5983.7, 6564, 
66.3000000000002, 10906.5, 3726.8, -662.700000000001, 50.5, 340413.6, 
17174, 9057.5, 669.6, -14799.7, 714.3, 2063.26, 1585.6, 1130.88, 
-1391.95, -2482.6, -4023.62, 864.2, -49.5, -1975.88, 6762.14, 
-5002.37, 341.6, 7934.2, -48.0999999999999, 2769.28, 4400.4, 
785.65, 1950.1, 3000, 11, 1348.4, 2101.2, 287129.3, -1481.4, 
-14051.7, 8585.9, 1405.4, -9983.9, 9342.7, -5178.1, 9493.1, 2761.3, 
-11092.3, 20498.9, 5000, 14891.9, 5985.5, 12195, 1424.2, 10957, 
7610.3, 58906.2, 8767.6, 10801.3, -969.200000000001, 31774.4, 
5190.1, -5097.7, 6268.8, 7229.1, 9443.8, -3498.2, 15182.2, -2676.8, 
5967, -1541.1, 3945.2, 161.5, 9419.4, -6746, 407, -3432.3, 6625.6, 
8157.5, 280, -3457.2, 13966.9, 7626.8, 7117.1, 1091.2, 6272.9, 
10714.8, 9215.2, 10118.8, -7.5, -71.7000000000007, 37503.8, 632, 
29919.9, -3470.6, 6037119.9, 40401.8, 19.4000000000001, 472.32, 
3089.85, 2212.73, 2183.52, 3060.3, 2883.71, 3008.2, 3022.2, -89.1800000000001, 
912, 2342.42, -8844.5, 2110.72, 157.469999999999, -1831.1, 3506.1, 
1766.02, -1748.82, 991.05, 641.87, -877.4, 949.1, 1048.25, 1236.9, 
10265.2, 1253.7, 2422.4, 1217, 2225.39, 3743.95, 1662.1, 13900.5, 
2466.08, -3790.2, -29593.2, 472181.9, 31416.8, 47504.6, 3142.1, 
706.9, 1762.2, -1789.9, 6586, -8080.2, -1895.8, 72.5, 4998.4, 
-4329, -3703.8, 5424.4, 31320.6, 24178.4, -11198.1, -2988.9, 
-4306.2, 7753, 1642.5, 24535.8, -33434, -3522.4, 6394.3, -2630, 
-1496.3, 27793.2, -4379, -11362.3, 8967, -125.6, 7099.8, -12514.2, 
188.1, -4294, 14630.5, 1916.6, -4994.6, -30639, 33729.6, 6896.2, 
9616.3, -13506.6, 6047, -6812.2, 5995.5, 1078.2, 10567.7, -596.700000000001, 
104616.3, 1651.2, 18995.7, 6588.9, 35111, -9451.5, 1366.9, -14121.3, 
-91.1500000000001, 1327.72, -651.19, 1088.79, 647.5, -2145.41, 
306.73, -444.14, 1530.51, 13023.7, 2780.4, 3043.7, -510.4, 1481.4, 
1888.8, -794.9, 5256, 855.9, 200, 983.22, 4360.01, 93.3099999999999, 
1798.6, 398.2, 15124.5, 745.73, 5478.5, 2874.05, -5708.03, 978.9, 
100, -734, -1322.79, 1095.37, 2867.2, -1439.59, 1456.6, -2355.17, 
15102.5, -1387.4, -5609.1, -95.3199999999999, 1922.87, -1043.43, 
454.1, -10070.81, -507.1, 945.7, -37.2, 213.38, 287.5, 1488.6, 
1558, 5347.6, 1188.7, 2779.13, 1300.23, 3749.23, 962.3, 2790.82, 
2123, 3795.55, 1414.5, -444, -129.6, -2535.1, -136.6, -131.68, 
1309.58, 14493.1, 3319.8, 313, 2872.2, 249.01, -53.8800000000001, 
843.18, 285.6, 184.6, -4173.1, 834.1, 14304.9, 2350.88, 1728.17, 
-376.71, 1541, -10381.5, 224, -471.12, 814.5, 1082.8, -4845.2, 
2000, -239.28, 1790.3, 1055.1, 241.29, 517.37, 985.17, 624, 1496.82, 
-13048.32, 477.8, 9819, 603.7, -900.85, 2017, 658.8, 7809.7, 
3785.15, 1954.44, 1022.9, 348.86, 2500, 3907.4, 1591.1, 824.4, 
1800.9, -310.4, 651.5, -2223.8, -2107.2, 623.7, 2836.15, -187.08, 
1826.56, 891.71, 8862251, 2930.41, -995.68, -472.8, 1272.8, 1064.72, 
395.51, 67711.1, 393.59, -1948.02, 6619.6, 715.6, -560.7, 840.3, 
40637.1, 8494, 29401.4, 6471756, 3932620, 181467.4, 4650.3, 1046.5, 
3888.3, 5448.7, 452.5, -379.799999999999, -3234.5, 28171.5, -16787.8, 
24963.1, -3119.8, 17437.1, -766.700000000001)), class = c("data.table", 
"data.frame"))

我现在想使用 diff 列将我的数据组织成组或间隔。

例如:

也许你可以给每个组一个值 group1 = 1group2 = 2 等,然后用这些组创建一个新列。 最后我想得到一个 table 每个组的条目总数,例如210 个条目被引用到 group1 = 1,它在 [0, 100].

区间内

Maël 为此使用 cut 是正确的,只是定义剪裁和标记的方式需要一些额外的步骤。

breaks <- c(-Inf, -10^(5:2), 0, 10^(2:5), Inf)
labels <- paste0("group", c(seq(10, 2, by = -2), seq(1, 9, by = 2)))

dt.data[, group := cut(diff, breaks = breaks, labels = labels)]

在我的示例中,我创建了以下中断和标签,但您可以轻松扩展或将它们用作硬编码中断和标签。

breaks
# [1]    -Inf -100000  -10000   -1000    -100       0     100    1000   10000  100000     Inf

labels
# [1] "group10" "group8"  "group6"  "group4"  "group2"  "group1"  "group3"  "group5"  "group7"  "group9"

输出每组仅 1 行,仅显示一次所有创建的组。

dt.data[, .SD[1], by = group]

    group nbVerbrauch hrVerbrauch      diff
1: group4         621       809.7    -188.7
2: group9     1143300     84105.0 1059195.0
3: group3        7521      7283.4     237.6
4: group5        5000      1800.8    3199.2
5: group6       40454     42267.4   -1813.4
6: group7       50413     14526.3   35886.7
7: group8         818     28796.0  -27978.0
8: group1        3500      3449.8      50.2
9: group2        1000      1032.9     -32.9

输出组数

dt.data[, .N, group]

或使用:

dt.data[, .(count = .N), by = group]

#     group count
# 1: group4    81
# 2: group9    24
# 3: group3   138
# 4: group5   360
# 5: group6   169
# 6: group7   135
# 7: group8    56
# 8: group1    16
# 9: group2    21