rshah
rshah

Reputation: 691

Concatenating rows based on range (variable) column condition

For subsequent discussion, I will refer to the following dataframe: https://gist.github.com/ryankshah/ab8c2b7c5e178264ccefbae9d72760ee

A shorter capture of this dput() can be found here:

structure(list(PacketTime = c(0.925717, 0.925967, 0.9262, 0.926368, 
0.966861, 0.966998, 0.9672, 0.967252, 0.971273, 0.97149, 0.971816, 
0.972113, 0.974991, 0.975093, 0.97521, 0.975273, 2.008958, 2.009109, 
2.009449, 2.009612, 2.01108, 2.011192, 2.011354, 2.011388, 2.015283, 
2.01536, 2.015468, 2.015525, 2.016604, 2.016834, 2.017415, 2.017646, 
2.019347, 2.019545, 2.019759, 2.019978, 2.020895, 2.021105, 2.023508, 
2.023639, 2.023769, 2.023843, 2.027671, 2.027725, 2.02788, 2.027916, 
2.028638, 2.02883, 2.03151, 2.031595, 2.031702, 2.031747, 2.034291, 
2.034404, 2.039741, 2.039864, 2.039985, 2.040038, 2.042009, 2.042255, 
2.043858, 2.043994, 2.044106, 2.044159, 2.04811, 2.048292, 2.048462, 
2.048528, 3.050371, 3.050611, 3.055923, 3.0562, 3.056505, 3.056714, 
8.059537, 8.059921, 8.065446, 8.065725, 8.066084, 8.066262, 10.068591, 
10.069067, 10.07296, 10.073275, 10.073676, 10.073876, 15.074687, 
15.075031, 15.078191, 15.078466, 15.078801, 15.079074, 18.081208, 
18.081529, 18.085248, 18.085535, 18.085852, 18.086052, 23.087208, 
23.087593, 23.090558, 23.090785, 23.091051, 23.091178, 27.09315, 
27.093459, 27.096607, 27.096871, 27.097215, 27.097397, 32.099606, 
32.100004, 32.102153, 32.102447, 32.102661, 32.102778, 37.105682, 
37.106026, 37.107854, 37.108097, 37.108414, 37.10868, 37.111986, 
37.11225, 37.112499, 37.112722, 42.114744, 42.115078, 42.117969, 
42.118193, 42.118482, 42.11864, 48.121045, 48.121391, 48.12679, 
48.127032, 48.127318, 48.127445, 53.130552, 53.130845, 53.136697, 
53.13683, 53.136959, 53.137048, 60.139012, 60.139349, 60.141249, 
60.141512, 60.141795, 60.142002, 60.145269, 60.145407, 60.145723, 
60.145829, 65.148214, 65.148629, 65.150792, 65.15101, 65.151288, 
65.151488, 73.155091, 73.155481, 73.158976, 73.159112, 73.159464, 
73.159645, 78.163605, 78.164009, 78.168708, 78.169007, 78.169318, 
78.169514, 87.170767, 87.171061, 87.176407, 87.176686, 87.177029, 
87.177226, 92.180694, 92.181003, 92.186155, 92.186468, 92.18692, 
92.187193, 102.187674, 102.18776, 102.190376, 102.190668, 102.193207, 
102.193441, 102.193629, 102.193805, 107.195208, 107.195504, 107.199008, 
107.199342, 107.199769, 107.200036, 117.199583, 117.199655, 118.203094, 
118.203531, 118.205494, 118.205809, 118.206103, 118.206409, 118.209557, 
118.209755, 123.212961, 123.213286, 123.215108, 123.215345, 123.215595, 
123.21583, 123.219189, 123.219368, 123.219602, 123.219702, 133.219802, 
133.219915, 135.224383, 135.224711, 135.22949, 135.229697, 135.230052, 
135.230166, 140.231358, 140.231709, 140.235145, 140.235354, 140.235666, 
140.23583, 150.23674, 150.236893, 153.237651, 153.237955, 153.240681, 
153.241032, 153.241138, 153.241311, 158.244289, 158.24462, 158.246344, 
158.246533, 158.246818, 158.247013, 158.25062, 158.250965, 158.251396, 
158.251727, 168.253167, 168.25327, 172.253859, 172.254289, 172.259665, 
172.259902, 172.26007, 172.260166, 177.262164, 177.262425, 177.265205, 
177.265375, 177.265631, 177.265884, 187.266422, 187.266505, 192.269399, 
192.269792, 192.27395, 192.274232, 192.274519, 192.274847, 197.279566, 
197.280221, 197.283799, 197.284061, 197.28468, 197.28491, 207.285048, 
207.285102, 213.286424, 213.286742, 213.291805, 213.292022, 213.292293, 
213.292509, 218.295248, 218.295628, 218.2975, 218.297738, 218.298062, 
218.298262, 218.301568, 218.301735, 218.301938, 218.302066, 228.301508, 
228.301602, 235.305332, 235.305773, 235.309398, 235.309731, 235.310093, 
235.310401, 240.312849, 240.313132, 240.315194, 240.315485, 240.315803, 
240.316064, 240.31901, 240.319262, 240.319539, 240.319755, 250.320398, 
250.320455, 258.321427, 258.321849, 258.326082, 258.32634, 258.32664, 
258.326817, 263.32921, 263.329591, 263.331642, 263.331896, 263.332199, 
263.332393, 263.335719, 263.335938, 263.336188, 263.336369, 273.337068, 
273.337128, 282.338967, 282.339414, 282.34244, 282.342766, 282.34309, 
282.343362, 287.345265, 287.345607, 287.348166, 287.348339, 287.348594, 
287.348817, 297.349787, 297.349865, 307.349457, 307.34957, 307.351337, 
307.3518, 307.354625, 307.355012, 307.35552, 307.35587, 312.35734, 
312.357705, 312.359736, 312.36004, 312.360364, 312.360594, 312.364214, 
312.364463, 312.364735, 312.36499, 322.366091, 322.366227, 332.366338, 
332.366534, 333.367324, 333.36794, 333.369832, 333.370364, 333.371064, 
333.371449, 333.373735, 333.374203, 333.374898, 333.375308, 338.3775, 
338.377843, 338.38372, 338.384043, 338.384348, 338.384588, 348.384979, 
348.38518, 358.385032, 358.386079, 360.385749, 360.386182, 360.388575, 
360.388942, 360.389326, 360.389634, 365.393852, 365.394483, 365.398596, 
365.399103, 365.399843, 365.400314, 375.401212, 375.401412, 385.402246, 
385.402379, 388.403104, 388.403558, 388.407001, 388.407347, 388.407757, 
388.407949, 393.410628, 393.411324, 393.416863, 393.417356, 393.418049, 
393.418364, 403.419292, 403.419493, 413.420496, 413.420703, 417.422362, 
417.423105, 417.424998, 417.425524, 417.426235, 417.426626, 417.4289, 
417.429372, 417.430061, 417.430587, 422.433468, 422.434207, 422.438868, 
422.439384, 422.440069, 422.440524, 432.441634, 432.44168, 442.441719, 
442.44192, 447.442671, 447.442965, 447.446516, 447.446798, 447.44712, 
447.447346, 452.450152, 452.450889, 452.456021, 452.456473, 452.457157, 
452.45767, 462.458991, 462.459146, 472.458653, 472.45875, 478.460478, 
478.461126, 478.462897, 478.463172, 478.463473, 478.46373, 478.467188, 
478.467475, 483.468957, 483.46949, 483.473127, 483.473498, 483.473933, 
483.474279, 493.475598, 493.475683, 503.475776, 503.475979, 510.477035, 
510.477734, 510.479687, 510.480173, 510.480865, 510.481371, 510.483715, 
510.484214, 510.484828, 510.485251, 515.48768, 515.488313, 515.493402, 
515.493923, 515.494545, 515.495049, 525.494754, 525.494827, 535.495316, 
535.495521, 543.497961, 543.498653, 543.503644, 543.504176), 
    FrameLen = c(44L, 276L, 44L, 276L, 44L, 276L, 44L, 276L, 
    44L, 276L, 44L, 276L, 44L, 276L, 44L, 276L, 285L, 44L, 285L, 
    44L, 44L, 276L, 44L, 276L, 44L, 276L, 44L, 276L, 285L, 44L, 
    285L, 44L, 44L, 276L, 44L, 276L, 285L, 44L, 44L, 276L, 44L, 
    276L, 44L, 276L, 44L, 276L, 288L, 44L, 44L, 276L, 44L, 276L, 
    285L, 44L, 44L, 276L, 44L, 276L, 288L, 44L, 44L, 276L, 44L, 
    276L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 
    289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 
    276L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 
    44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 
    276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 
    44L, 276L, 44L, 276L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 
    276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 
    44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 44L, 
    276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 
    44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 
    44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 
    45L, 56L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 
    276L, 44L, 276L, 45L, 56L, 289L, 44L, 44L, 276L, 44L, 276L, 
    44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 44L, 276L, 44L, 
    276L, 45L, 56L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 
    44L, 276L, 44L, 276L, 45L, 56L, 289L, 44L, 44L, 276L, 44L, 
    276L, 289L, 44L, 44L, 276L, 44L, 276L, 44L, 276L, 44L, 276L, 
    45L, 56L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 
    276L, 44L, 276L, 45L, 56L, 289L, 44L, 44L, 276L, 44L, 276L, 
    289L, 44L, 44L, 276L, 44L, 276L, 45L, 56L, 289L, 44L, 44L, 
    276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 44L, 276L, 
    44L, 276L, 45L, 56L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 
    44L, 44L, 276L, 44L, 276L, 44L, 276L, 44L, 276L, 45L, 56L, 
    289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 
    276L, 44L, 276L, 44L, 276L, 45L, 56L, 289L, 44L, 44L, 276L, 
    44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 45L, 56L, 45L, 
    56L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 
    44L, 276L, 44L, 276L, 44L, 276L, 45L, 56L, 45L, 56L, 289L, 
    44L, 44L, 276L, 44L, 276L, 44L, 276L, 44L, 276L, 289L, 44L, 
    44L, 276L, 44L, 276L, 45L, 56L, 45L, 56L, 289L, 44L, 44L, 
    276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 45L, 56L, 
    45L, 56L, 289L, 44L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 
    276L, 44L, 276L, 45L, 56L, 45L, 56L, 289L, 44L, 44L, 276L, 
    44L, 276L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 
    276L, 45L, 56L, 45L, 56L, 289L, 44L, 44L, 276L, 44L, 276L, 
    289L, 44L, 44L, 276L, 44L, 276L, 45L, 56L, 45L, 56L, 289L, 
    44L, 44L, 276L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 
    44L, 276L, 45L, 56L, 45L, 56L, 289L, 44L, 44L, 276L, 44L, 
    276L, 44L, 276L, 44L, 276L, 289L, 44L, 44L, 276L, 44L, 276L, 
    45L, 56L, 45L, 56L, 289L, 44L, 44L, 276L), IPLen = c(40L, 
    272L, 40L, 272L, 40L, 272L, 40L, 272L, 40L, 272L, 40L, 272L, 
    40L, 272L, 40L, 272L, 281L, 40L, 281L, 40L, 40L, 272L, 40L, 
    272L, 40L, 272L, 40L, 272L, 281L, 40L, 281L, 40L, 40L, 272L, 
    40L, 272L, 281L, 40L, 40L, 272L, 40L, 272L, 40L, 272L, 40L, 
    272L, 284L, 40L, 40L, 272L, 40L, 272L, 281L, 40L, 40L, 272L, 
    40L, 272L, 284L, 40L, 40L, 272L, 40L, 272L, 40L, 272L, 40L, 
    272L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 
    40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 
    272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 
    40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 
    40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 
    40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 
    40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 
    285L, 40L, 40L, 272L, 40L, 272L, 40L, 272L, 40L, 272L, 285L, 
    40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 
    285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 
    272L, 285L, 40L, 40L, 272L, 40L, 272L, 41L, 52L, 285L, 40L, 
    40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 41L, 
    52L, 285L, 40L, 40L, 272L, 40L, 272L, 40L, 272L, 285L, 40L, 
    40L, 272L, 40L, 272L, 40L, 272L, 40L, 272L, 41L, 52L, 285L, 
    40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 
    41L, 52L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 
    272L, 40L, 272L, 40L, 272L, 40L, 272L, 41L, 52L, 285L, 40L, 
    40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 41L, 
    52L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 
    40L, 272L, 41L, 52L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 
    40L, 40L, 272L, 40L, 272L, 40L, 272L, 40L, 272L, 41L, 52L, 
    285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 
    272L, 40L, 272L, 40L, 272L, 41L, 52L, 285L, 40L, 40L, 272L, 
    40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 40L, 272L, 40L, 
    272L, 41L, 52L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 
    40L, 272L, 40L, 272L, 41L, 52L, 41L, 52L, 285L, 40L, 40L, 
    272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 40L, 272L, 
    40L, 272L, 41L, 52L, 41L, 52L, 285L, 40L, 40L, 272L, 40L, 
    272L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 
    41L, 52L, 41L, 52L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 
    40L, 40L, 272L, 40L, 272L, 41L, 52L, 41L, 52L, 285L, 40L, 
    40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 41L, 
    52L, 41L, 52L, 285L, 40L, 40L, 272L, 40L, 272L, 40L, 272L, 
    40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 41L, 52L, 41L, 
    52L, 285L, 40L, 40L, 272L, 40L, 272L, 285L, 40L, 40L, 272L, 
    40L, 272L, 41L, 52L, 41L, 52L, 285L, 40L, 40L, 272L, 40L, 
    272L, 40L, 272L, 285L, 40L, 40L, 272L, 40L, 272L, 41L, 52L, 
    41L, 52L, 285L, 40L, 40L, 272L, 40L, 272L, 40L, 272L, 40L, 
    272L, 285L, 40L, 40L, 272L, 40L, 272L, 41L, 52L, 41L, 52L, 
    285L, 40L, 40L, 272L), TCPLen = c(0L, 232L, 0L, 232L, 0L, 
    232L, 0L, 232L, 0L, 232L, 0L, 232L, 0L, 232L, 0L, 232L, 241L, 
    0L, 241L, 0L, 0L, 232L, 0L, 232L, 0L, 232L, 0L, 232L, 241L, 
    0L, 241L, 0L, 0L, 232L, 0L, 232L, 241L, 0L, 0L, 232L, 0L, 
    232L, 0L, 232L, 0L, 232L, 244L, 0L, 0L, 232L, 0L, 232L, 241L, 
    0L, 0L, 232L, 0L, 232L, 244L, 0L, 0L, 232L, 0L, 232L, 0L, 
    232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 
    232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 
    232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 
    232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 
    232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 0L, 232L, 0L, 
    232L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 
    232L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 
    232L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 
    0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 
    0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 1L, 
    0L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 
    232L, 1L, 0L, 245L, 0L, 0L, 232L, 0L, 232L, 0L, 232L, 245L, 
    0L, 0L, 232L, 0L, 232L, 0L, 232L, 0L, 232L, 1L, 0L, 245L, 
    0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 1L, 
    0L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 
    232L, 0L, 232L, 0L, 232L, 1L, 0L, 245L, 0L, 0L, 232L, 0L, 
    232L, 245L, 0L, 0L, 232L, 0L, 232L, 1L, 0L, 245L, 0L, 0L, 
    232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 1L, 0L, 245L, 
    0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 0L, 
    232L, 0L, 232L, 1L, 0L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 
    0L, 0L, 232L, 0L, 232L, 0L, 232L, 0L, 232L, 1L, 0L, 245L, 
    0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 0L, 
    232L, 0L, 232L, 1L, 0L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 
    0L, 0L, 232L, 0L, 232L, 1L, 0L, 1L, 0L, 245L, 0L, 0L, 232L, 
    0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 0L, 232L, 0L, 232L, 
    1L, 0L, 1L, 0L, 245L, 0L, 0L, 232L, 0L, 232L, 0L, 232L, 0L, 
    232L, 245L, 0L, 0L, 232L, 0L, 232L, 1L, 0L, 1L, 0L, 245L, 
    0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 1L, 
    0L, 1L, 0L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 
    0L, 232L, 1L, 0L, 1L, 0L, 245L, 0L, 0L, 232L, 0L, 232L, 0L, 
    232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 232L, 1L, 0L, 1L, 
    0L, 245L, 0L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 
    232L, 1L, 0L, 1L, 0L, 245L, 0L, 0L, 232L, 0L, 232L, 0L, 232L, 
    245L, 0L, 0L, 232L, 0L, 232L, 1L, 0L, 1L, 0L, 245L, 0L, 0L, 
    232L, 0L, 232L, 0L, 232L, 0L, 232L, 245L, 0L, 0L, 232L, 0L, 
    232L, 1L, 0L, 1L, 0L, 245L, 0L, 0L, 232L), Movement = c(3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 3, 3)), row.names = c(NA, 500L), class = "data.frame")

The aim here is to group all the packets where the PacketTime is similar. This can be done using the following:

brks <- seq(trunc(min(pump_packets$PacketTime)), max(pump_packets$PacketTime) + 5, 5)
pump_packets$Interval <- cut(pump_packets$PacketTime, breaks = brks, labels = brks[-length(brks)], right = FALSE)

However, this is for a fixed interval. In this case, the grouping is for packet times in the range of a 1s to 60s gap, which repeats (i.e. when it reaches the 60s gap, the next grouping will be starting at 1s). As you can see the current solution for a fixed interval does not take the range interval into account. As well as this, some of these crossover (i.e. 1480s also includes part of 1481s). What makes this somewhat simpler is that each of the groups are separated by an n second timing window (via Python time.sleep(n)), where n is in range(1, 61) (1s to 60s).

Furthermore, after each interval between packets - there is a 5s sleep (break). An example of what I mean by the interval in a more visual way can be seen below.

enter image description here

How can this be achieved? (This is a variable version of this post Concatenating data frame rows based on column condition)

EDIT: I will eventually use the grouped data to group by the interval the packets are in, such as follows:

pump_packets <- pump_packets %>%
  group_by(Interval) %>%
  summarise(
    PTime=max(PacketTime)-min(PacketTime),
    FLen=list(FrameLen),
    ILen=list(IPLen),
    Movement=3
  ) %>%
  rename(PacketTime=PTime) %>%
  rename(FrameLen=FLen) %>%
  rename(IPLen=ILen)

Ultimately, there should be a total of 300 samples/groups.

Upvotes: 0

Views: 104

Answers (1)

Oliver
Oliver

Reputation: 8602

It is quite unclear exactly what you want to achieve, so this might be a long shot.

There seems to be 2 problems included in this question:

  1. Create a sequence with multiple by elements
  2. group a certain column by the sequence generated in 1.

Create a sequence with multiple by elements

Now the for 1. I'm unaware of any inbuild or package function, even though I don't doubt it already exists. We can however simply create our own seqv function with vectorized by elements.

seqv <- function(from, to, by){
  diff <- to - from
  if((n <- diff / sum(by)) < 1){
    n <- 1
  }else{
    n <- ceiling(n)
  }
  out <- c(from, from + cumsum(rep(by, n)))
  out[out <= to]
}

Usage example:

mi <- trunc(min(pump_packets$PacketTime))
ma <- max(pump_packets$PacketTime)
ra <- 1:60
ra[60] <- ra[60] + 5
cuts <- seqv(mi, ma + 5, ra)
cuts[c(1:6, (length(cuts) - 5):length(cuts))]
[1]     0     1     3     6    10    15 10400 10450 10501 10553 10606 10660
length(cuts)
[1] 355

now this output does not include the max value of 10660.46 and the length is not 300, this does however follow the description in the question, as such I am not sure where the misunderstanding has happened. For now I'll add a bit to the last value to include the max value.

cuts[length(cuts)] <- cuts[length(cuts)] + 1

group a certain column by the sequence generated in 1.

Now the main part was really in 1. so here We can just use the cut function to create our groupings

pump_packets$group <- 
  cut(pump_packets$PacketTime, breaks = cuts, right = FALSE, dig.lab = 12)

pump_packets_summary <- pump_packets %>%
  group_by(group) %>%
  summarise(
    PacketTime = max(PacketTime) - min(PacketTime),
    FrameLen = list(FrameLen),
    IPLen = list(IPLen),
    n = n()
  ) 
head(pump_packets_summary)
# A tibble: 6 x 5
  group   PacketTime FrameLen   IPLen          n
  <fct>        <dbl> <list>     <list>     <int>
1 [0,1)      0.0496  <int [16]> <int [16]>    16
2 [1,3)      0.0396  <int [52]> <int [52]>    52
3 [3,6)      0.00634 <int [6]>  <int [6]>      6
4 [6,10)     0.00672 <int [6]>  <int [6]>      6
5 [10,15)    0.00529 <int [6]>  <int [6]>      6
6 [15,21)    3.01    <int [12]> <int [12]>    12
tail(pump_packets_summary )
# A tibble: 6 x 5
  group         PacketTime FrameLen   IPLen          n
  <fct>              <dbl> <list>     <list>     <int>
1 [10351,10400)       30.0 <int [8]>  <int [8]>      8
2 [10400,10450)       41.0 <int [20]> <int [20]>    20
3 [10450,10501)       42.0 <int [24]> <int [24]>    24
4 [10501,10553)       43.0 <int [20]> <int [20]>    20
5 [10553,10606)       44.0 <int [20]> <int [20]>    20
6 [10606,10661)       50.0 <int [16]> <int [16]>    16

Which might be the desired result.

Upvotes: 2

Related Questions