1

This is an updated post with a better depiction of actual data and also incorporates earlier comments from John. Thanks again to him.

I have also made the data available directly through dput()

I have two separate data frames in R. The variables of interest are dates that are formatted as serial numbers as I think they are a bit easier in the number format. Although note they are not integers, rather they are long decimals in order to keep accuracy and decrease repeats of identical values. The first data set is simply a vector of one DateTime number.

one <-  structure(list(DateTimeNumber = c(40603.91729, 40604.00056, 40604.08381, 
40604.16729, 40604.25058, 40604.33375, 40604.41716, 40604.50063, 
40604.58407, 40604.66697, 40604.75061, 40604.83431, 40604.91721, 
40605.00063, 40605.08396, 40605.16725, 40605.25057, 40605.33392, 
40605.41749, 40605.50069, 40605.58431, 40605.66728, 40605.75072, 
40605.83424, 40605.91791, 40606.00063, 40606.0839, 40606.16729, 
40606.25051, 40606.33388, 40606.41729, 40606.50061, 40606.5839, 
40606.66753, 40606.83458, 40606.91728, 40607.00073, 40607.08491, 
40607.16772, 40607.25047, 40607.33428, 40607.41721, 40607.50061, 
40607.58429, 40607.66797, 40607.75061, 40607.83462, 40608.00155, 
40608.0841, 40608.16725, 40608.2505, 40608.33395, 40608.41729, 
40608.50089, 40608.58458, 40608.66751, 40608.83428, 40608.91729, 
40609.00061, 40609.08429, 40609.1678, 40609.25061, 40609.50123, 
40609.58418, 40609.66758, 40609.75169, 40609.83527, 40609.91729, 
40610.00061, 40610.08396, 40610.16789, 40610.2505, 40610.33407, 
40610.41728, 40610.50081, 40610.58406, 40610.66742, 40610.91834, 
40611.00116, 40611.08382, 40611.16728, 40611.25096, 40611.33396, 
40611.41728, 40611.50068, 40611.58384, 40611.66738, 40611.75063, 
40611.83389, 40611.91729, 40612.00067, 40612.0839, 40612.16749, 
40612.25061, 40612.33395, 40612.41714, 40612.5009, 40612.58378, 
40612.66764, 40612.75058, 40612.83396, 40612.91763, 40613.00056, 
40613.08396, 40613.16749, 40613.25127, 40613.33383, 40613.41743, 
40613.50096, 40613.58421, 40613.66764, 40613.75066, 40613.83536, 
40613.91729, 40614.00063, 40614.08389, 40614.16721, 40614.25061, 
40614.33388, 40614.41721, 40614.50083, 40614.5845, 40614.66775, 
40614.75064, 40614.83472, 40614.91744, 40615.00063, 40615.08424, 
40615.16773, 40615.25091, 40615.33381, 40615.41749, 40615.50058, 
40615.58466, 40615.66762, 40615.75058, 40615.83426, 40615.91757, 
40616.00153, 40616.08382, 40616.16792, 40616.25083, 40616.33428, 
40616.41718, 40616.50061, 40616.58456, 40616.66714, 40616.75063, 
40616.83397, 40616.91865, 40617.00083, 40617.08383, 40617.16714, 
40617.25063, 40617.33416, 40617.41785, 40617.50083, 40617.58404, 
40617.66794, 40617.75056, 40617.83499, 40617.91745, 40618.00084, 
40618.08405, 40618.16728, 40618.25047, 40618.3341, 40618.41844, 
40618.50128, 40618.58484, 40618.66728, 40618.75061, 40618.91728, 
40619.00098, 40619.08395, 40619.16728, 40619.25083, 40619.33395, 
40619.41795, 40619.50057, 40619.58403, 40619.66882, 40620.00118, 
40620.08396, 40620.1675, 40620.25049, 40620.33403, 40620.41763, 
40620.50089, 40620.5842, 40620.66799, 40620.83431, 40620.91729, 
40621.00122, 40621.08361, 40621.16714, 40621.25065, 40621.33427, 
40621.41763, 40621.50029, 40621.58416, 40621.66728, 40621.75056, 
40621.83456, 40621.91791, 40622.00096, 40622.08395, 40622.16728, 
40622.25047, 40622.33398, 40622.41709, 40622.50082, 40622.58431, 
40622.66833, 40622.75056, 40622.83521, 40622.91714, 40623.00082, 
40623.08395, 40623.16725, 40623.25047, 40623.33413, 40623.41797, 
40623.50082, 40623.58456, 40623.66809, 40623.75061, 40623.8355, 
40623.91729, 40624.00097, 40624.08411, 40624.16697, 40624.25185, 
40624.33389, 40624.41781, 40624.50089, 40624.58391, 40624.66722, 
40624.75122, 40624.83465, 40624.91714, 40625.00049, 40625.08402, 
40625.25064, 40625.33463, 40625.41718, 40625.50047, 40625.58382, 
40625.66721, 40625.75118, 40625.83395, 40625.91721, 40626.00086, 
40626.08384, 40626.16722, 40626.25061, 40626.33381, 40626.41722, 
40626.50089, 40626.58422, 40626.66729, 40626.75049, 40626.83383, 
40626.9172, 40627.00037, 40627.08464, 40627.16714, 40627.25047, 
40627.33384, 40627.41715, 40627.50083, 40627.58382, 40627.66728, 
40627.75046, 40627.8345, 40627.91716, 40628.00063, 40628.08397, 
40628.16791, 40628.33451, 40628.41738, 40628.5008, 40628.75127, 
40628.9188, 40629.00051, 40629.08449, 40629.16833, 40629.25031, 
40629.33458, 40629.41715, 40629.50126, 40629.58449, 40629.66799, 
40629.75126, 40630.08416, 40630.16781, 40630.25061, 40630.33398, 
40630.41731, 40630.50083, 40630.58373, 40630.66725, 40630.75047, 
40630.83398, 40630.91696, 40631.00072, 40631.08431, 40631.16729, 
40631.25071, 40631.33395, 40631.41782, 40631.50061, 40631.58417, 
40631.66736, 40631.75122, 40631.91715, 40632.00049, 40632.08396, 
40632.16722, 40632.25167, 40632.33409, 40632.41714, 40632.50061, 
40632.58394, 40632.66884, 40632.75138, 40632.91731, 40633.00043, 
40633.08464, 40633.16728, 40633.25063, 40633.33388, 40633.41728, 
40633.50061, 40633.58551, 40633.66787, 40633.75162, 40633.83457, 
40633.91729, 40634.00065, 40634.08392, 40634.16814, 40634.25166, 
40634.33395, 40634.41729, 40634.50054, 40634.5839, 40634.6672, 
40634.75063, 40634.91784, 40635.00076, 40635.08394, 40635.16728, 
40635.25073, 40635.33396, 40635.41729, 40635.50061, 40635.58458, 
40635.66728, 40635.83461, 40635.91788, 40636.00116, 40636.08382, 
40636.16822, 40636.25096, 40636.33382, 40636.41714, 40636.50094, 
40636.58391, 40636.66799, 40636.75058, 40636.9178, 40637.08383, 
40637.25164, 40637.33535, 40637.41885, 40637.58422, 40637.66887, 
40637.75133, 40637.83466, 40637.918, 40638.00051, 40638.08382, 
40638.16723, 40638.33464, 40638.41826, 40638.58391, 40638.66721, 
40638.75065, 40638.83396, 40638.91728, 40639.00063, 40639.08391, 
40639.16714, 40639.25051, 40639.33382, 40639.41714, 40639.50095, 
40639.66811, 40639.75065, 40639.83406, 40639.91729, 40640.00068, 
40640.08396, 40640.1675, 40640.25089, 40640.33395, 40640.41728, 
40640.5005, 40640.58455, 40640.66728, 40640.75063, 40640.83478, 
40641.00169, 40641.08388, 40641.16722, 40641.25132, 40641.33381, 
40641.41729, 40641.50078, 40641.58383, 40641.66743, 40641.75061, 
40641.83396, 40641.91721, 40642.00065, 40642.08381, 40642.16718, 
40642.25053, 40642.33382, 40642.4175, 40642.50063, 40642.58389, 
40642.66758, 40642.75083, 40642.83409, 40642.91759, 40643.00063, 
40643.08382, 40643.1673, 40643.33461, 40643.41881, 40643.50093, 
40643.58537, 40643.66749, 40643.75199, 40643.83389, 40643.91688, 
40644.00057, 40644.08396, 40644.16714, 40644.25115, 40644.33395, 
40644.41729, 40644.50049, 40644.58456, 40644.6675, 40644.75063, 
40644.83465, 40644.91748, 40645.00058, 40645.08383, 40645.16729, 
40645.25049, 40645.33361, 40645.41728, 40645.50156, 40645.58396, 
40645.66716, 40645.75058, 40645.83382, 40645.91715, 40646.00049, 
40646.0836, 40646.16718, 40646.25061, 40646.33394, 40646.41744, 
40646.50083, 40646.58396, 40646.66727, 40646.75054, 40646.83388, 
40646.91809, 40647.00049, 40647.08381, 40647.16697, 40647.25082, 
40647.33394, 40647.41722, 40647.50056, 40647.58388, 40647.66697, 
40647.75051, 40647.83388, 40647.91715, 40648.00051, 40648.08395, 
40648.16748, 40648.25078, 40648.33395, 40648.41728, 40648.50078, 
40648.58391, 40648.667, 40648.75086, 40648.83362, 40648.91721, 
40649.00057, 40649.08382, 40649.16727, 40649.25056, 40649.33389, 
40649.41693, 40649.50063, 40649.58462, 40649.66749, 40649.75061, 
40649.83398, 40649.91819, 40650.00056, 40650.08413, 40650.16729, 
40650.25063, 40650.33389, 40650.41697, 40650.50031, 40650.58521, 
40650.66747, 40650.75125, 40650.83395, 40650.91757, 40651.00118, 
40651.08396, 40651.16731, 40651.25112, 40651.3341, 40651.41712, 
40651.50074, 40651.58362, 40651.6672, 40651.75198, 40651.83409, 
40651.91818, 40652.00116, 40652.0841, 40652.16749, 40652.2508, 
40652.33383, 40652.41694, 40652.50049, 40652.58465, 40652.66727, 
40652.75065, 40652.83422, 40652.91756, 40653.00063, 40653.08534, 
40653.16722, 40653.25146, 40653.33397, 40653.41722, 40653.50145, 
40653.58397, 40653.66728, 40653.75124, 40653.83395, 40653.91722, 
40654.00051, 40654.08383, 40654.16714, 40654.25066, 40654.33416, 
40654.41733, 40654.50211, 40654.58433, 40654.66764, 40654.75097, 
40654.91795, 40655.00134, 40655.0841, 40655.16785, 40655.25167, 
40655.33395, 40655.41729, 40655.50213, 40655.58464, 40655.66715, 
40655.75061, 40655.83395, 40655.91757, 40656.00096, 40656.08446, 
40656.16721, 40656.25065, 40656.33381, 40656.41797, 40656.50066, 
40656.58476, 40656.66744, 40656.75088, 40656.83412, 40656.91771, 
40657.00082, 40657.08432, 40657.1686, 40657.25125, 40657.33545, 
40657.41731, 40657.50083, 40657.58395, 40657.66753, 40657.75196, 
40657.83419, 40657.91792, 40658.00054, 40658.08413, 40658.16764, 
40658.25147, 40658.33523, 40658.41789, 40658.50063, 40658.58388, 
40658.75137, 40658.83395, 40658.917, 40659.08395, 40659.16764, 
40659.25049, 40659.33422, 40659.41731, 40659.58464, 40659.66722, 
40659.75125, 40659.83395, 40659.91752, 40660.00063, 40660.08493, 
40660.16764, 40660.3345, 40660.41861, 40660.50184, 40660.66778, 
40660.75157, 40660.91723, 40661.00025, 40661.08362, 40661.16763, 
40661.25117, 40661.33389, 40661.50155, 40661.75153, 40661.8344, 
40662.08501, 40662.16708, 40662.25063, 40662.33416, 40662.41729, 
40662.50049, 40662.58422, 40662.6675, 40662.75049, 40662.8336, 
40662.91742, 40663.00097, 40663.08416, 40663.16728, 40663.25128, 
40663.33388, 40663.41722, 40663.50028, 40663.58396, 40663.66727, 
40663.75065, 40663.83403, 40663.91749, 40664.00061, 40664.08417, 
40664.16728, 40664.25056, 40664.33361, 40664.41716, 40664.50061, 
40664.66772, 40664.75089, 40664.83389, 40664.91729, 40665.00061, 
40665.08439, 40665.16795, 40665.25131, 40665.33434, 40665.41786, 
40665.50123, 40665.58383, 40665.66729, 40665.75065, 40665.83396, 
40665.91736, 40666.00049, 40666.08363, 40666.16757, 40666.25061, 
40666.33391, 40666.41729, 40666.50117, 40666.5839, 40666.66764, 
40666.75124, 40666.83403, 40666.91728, 40667.00061, 40667.08425, 
40667.16729, 40667.25063, 40667.33395, 40667.41736, 40667.50116, 
40667.58395, 40667.6675, 40667.75155, 40667.83382, 40667.91723, 
40668.00049, 40668.08396, 40668.16701, 40668.25132, 40668.33544, 
40668.50122, 40668.66836, 40668.75192, 40668.91794, 40669.00096, 
40669.08383, 40669.16856, 40669.25063, 40669.33381, 40669.41729, 
40669.50153, 40669.58451, 40669.83457, 40669.91729, 40670.00025, 
40670.08384, 40670.16728, 40670.25052, 40670.33477, 40670.41729, 
40670.50156, 40670.58438, 40670.66714, 40670.75127, 40670.83479, 
40670.91729, 40671.00212, 40671.08463, 40671.16714, 40671.25049, 
40671.33395, 40671.41714, 40671.50089, 40671.58464, 40671.6688, 
40672.00074, 40672.08462, 40672.16784, 40672.25049, 40672.33392, 
40672.41731, 40672.50057, 40672.58382, 40672.66749, 40672.75063, 
40672.83388, 40672.91744, 40673.00054, 40673.08381, 40673.16737, 
40673.25061, 40673.33405, 40673.41726, 40673.50061, 40673.58382, 
40673.66881, 40673.75056, 40673.83382, 40673.91722, 40674.00029, 
40674.08381, 40674.16729, 40674.25047, 40674.33383, 40674.41731, 
40674.50063, 40675.00089, 40675.08405, 40675.16719, 40675.75215, 
40676.16752, 40676.25063, 40676.33383, 40676.41715, 40676.50061, 
40676.58396, 40676.6673, 40676.75067, 40676.83388, 40676.91756, 
40677.00054, 40677.08389, 40677.16715, 40677.25063, 40677.33396, 
40677.41691, 40677.50083, 40677.58363, 40677.66786, 40677.75072, 
40678.25118, 40678.33396, 40678.41721, 40678.50063, 40678.58477, 
40678.66763, 40678.75064, 40678.8347, 40678.91882, 40679.00051, 
40679.08485, 40679.1673, 40679.25056, 40679.33395, 40679.4175, 
40679.5005, 40679.58382, 40679.66828, 40679.75198, 40679.83455, 
40679.91731, 40680.00056, 40680.0839, 40680.16697, 40680.2503, 
40680.33389, 40680.41728, 40680.50118, 40680.58395, 40680.66856, 
40680.75061, 40680.83544, 40680.91764, 40681.00081, 40681.0839, 
40681.16722, 40681.25049, 40681.33382, 40681.41715, 40681.50066, 
40681.58431, 40681.66723, 40681.75075, 40681.83448, 40681.9175, 
40682.00074, 40682.08396, 40682.16828, 40682.25071, 40682.33396, 
40682.41728, 40682.50057, 40682.58383, 40682.66708, 40682.75057, 
40682.8352, 40682.91721, 40683.00071, 40683.08426, 40683.16729, 
40683.25063, 40683.33396, 40683.41757, 40683.50061, 40683.58385, 
40683.66728, 40683.75072, 40683.83424, 40683.91725, 40684.00057, 
40684.08398, 40684.16757, 40684.25123, 40684.33411, 40684.41756, 
40684.50063, 40684.58469, 40684.66797, 40684.75056, 40684.83515, 
40684.9175, 40685.00056, 40685.08363, 40685.16725, 40685.25111, 
40685.33431, 40685.41774, 40685.50063, 40685.58388, 40685.66763, 
40685.75057, 40685.83383, 40685.91729, 40686.0009, 40686.08388, 
40686.16729, 40686.25097, 40686.33417, 40686.41816, 40686.50096, 
40686.58384, 40686.66742, 40686.75056, 40686.83424, 40686.91728, 
40687.0009, 40687.08424, 40687.16721, 40687.25096, 40687.33382, 
40687.41728, 40687.50064, 40687.58407, 40687.66826, 40687.75047, 
40687.83448, 40687.91797, 40688.00061, 40688.08384, 40688.16735, 
40688.25153, 40688.33396, 40688.41764, 40688.58465, 40688.66817, 
40688.75083, 40688.83455, 40688.91764, 40689.00096, 40689.08425, 
40689.16745, 40689.25059, 40689.33451, 40689.41782, 40689.50063, 
40689.58411, 40689.66735, 40689.75097, 40689.83431, 40689.91878, 
40690.0019, 40690.08403, 40690.16769, 40690.25049, 40690.33396, 
40690.41748, 40690.50056, 40690.58395, 40690.66764, 40690.75113, 
40690.83462, 40690.9173, 40691.00057, 40691.0837, 40691.16729, 
40691.25097, 40691.33448, 40691.41782, 40691.50061, 40691.58397, 
40691.66818, 40691.75059, 40691.8347, 40691.91725, 40692.00118, 
40692.08404, 40692.16784, 40692.25189, 40692.33422, 40692.41866, 
40692.50097, 40692.58546, 40692.66756, 40692.75125, 40692.83431, 
40692.91729, 40693.00122, 40693.08399, 40693.16756, 40693.25082, 
40693.33381)), .Names = "DateTimeNumber", class = "data.frame", row.names = c(NA, 
-999L))

The head() and dim() of which are below

head(one)
      DateTimeNumber
1 40603.917289999997593
2 40604.000560000000405
3 40604.083809999996447
4 40604.167289999997593
5 40604.250579999999900
6 40604.333749999997963

dim(one)
[1] 999   1

The second table has a start DateTime number and an End DateTime number as well as a unique ID and can be found here.

    two <- structure(list(ClstrID = structure(c(1L, 2L, 3L, 4L, 6L, 5L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 
34L, 33L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 
46L, 47L, 52L, 49L, 50L, 51L, 48L, 53L, 54L, 55L, 57L, 56L, 58L, 
59L, 60L, 61L, 63L, 62L, 65L, 64L, 66L, 67L, 68L, 69L, 70L, 72L, 
71L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 82L, 81L, 83L, 84L, 
85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 
98L, 99L, 100L, 101L, 102L, 104L, 103L, 122L, 105L, 106L, 107L, 
108L, 109L, 115L, 110L, 111L, 112L, 113L, 114L, 116L, 119L, 118L, 
117L, 120L, 121L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 
131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 
142L, 143L, 144L, 145L, 146L, 147L, 148L, 150L, 149L, 151L, 152L, 
153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 
164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L
), .Label = c("ClstrColoP01_001", "ClstrColoP01_002", "ClstrColoP01_003", 
"ClstrColoP01_004", "ClstrColoP01_005", "ClstrColoP01_006", "ClstrColoP01_007", 
"ClstrColoP01_008", "ClstrColoP01_009", "ClstrColoP01_010", "ClstrColoP01_011", 
"ClstrColoP01_012", "ClstrColoP01_013", "ClstrColoP01_014", "ClstrColoP01_015", 
"ClstrColoP01_016", "ClstrColoP01_017", "ClstrColoP01_018", "ClstrColoP01_019", 
"ClstrColoP01_020", "ClstrColoP01_021", "ClstrColoP01_022", "ClstrColoP01_023", 
"ClstrColoP01_024", "ClstrColoP01_025", "ClstrColoP01_026", "ClstrColoP01_027", 
"ClstrColoP01_028", "ClstrColoP01_029", "ClstrColoP01_030", "ClstrColoP01_031", 
"ClstrColoP01_032", "ClstrColoP01_033", "ClstrColoP01_034", "ClstrColoP01_035", 
"ClstrColoP01_036", "ClstrColoP01_037", "ClstrColoP01_038", "ClstrColoP01_039", 
"ClstrColoP01_040", "ClstrColoP01_041", "ClstrColoP01_042", "ClstrColoP01_043", 
"ClstrColoP01_044", "ClstrColoP01_045", "ClstrColoP01_046", "ClstrColoP01_047", 
"ClstrColoP01_048", "ClstrColoP01_049", "ClstrColoP01_050", "ClstrColoP01_051", 
"ClstrColoP01_052", "ClstrColoP01_053", "ClstrColoP01_054", "ClstrColoP01_055", 
"ClstrColoP01_056", "ClstrColoP01_057", "ClstrColoP01_058", "ClstrColoP01_059", 
"ClstrColoP01_060", "ClstrColoP01_061", "ClstrColoP01_062", "ClstrColoP01_063", 
"ClstrColoP01_064", "ClstrColoP01_065", "ClstrColoP01_066", "ClstrColoP01_067", 
"ClstrColoP01_068", "ClstrColoP01_069", "ClstrColoP01_070", "ClstrColoP01_071", 
"ClstrColoP01_072", "ClstrColoP01_073", "ClstrColoP01_074", "ClstrColoP01_075", 
"ClstrColoP01_076", "ClstrColoP01_077", "ClstrColoP01_078", "ClstrColoP01_079", 
"ClstrColoP01_080", "ClstrColoP01_081", "ClstrColoP01_082", "ClstrColoP01_083", 
"ClstrColoP01_084", "ClstrColoP01_085", "ClstrColoP01_086", "ClstrColoP01_087", 
"ClstrColoP01_088", "ClstrColoP01_089", "ClstrColoP01_090", "ClstrColoP01_091", 
"ClstrColoP01_092", "ClstrColoP01_093", "ClstrColoP01_094", "ClstrColoP01_095", 
"ClstrColoP01_096", "ClstrColoP01_097", "ClstrColoP01_098", "ClstrColoP01_099", 
"ClstrColoP01_100", "ClstrColoP01_101", "ClstrColoP01_102", "ClstrColoP01_103", 
"ClstrColoP01_104", "ClstrColoP01_105", "ClstrColoP01_106", "ClstrColoP01_107", 
"ClstrColoP01_108", "ClstrColoP01_109", "ClstrColoP01_110", "ClstrColoP01_111", 
"ClstrColoP01_112", "ClstrColoP01_113", "ClstrColoP01_114", "ClstrColoP01_115", 
"ClstrColoP01_116", "ClstrColoP01_117", "ClstrColoP01_118", "ClstrColoP01_119", 
"ClstrColoP01_120", "ClstrColoP01_121", "ClstrColoP01_122", "ClstrColoP01_123", 
"ClstrColoP01_124", "ClstrColoP01_125", "ClstrColoP01_126", "ClstrColoP01_127", 
"ClstrColoP01_128", "ClstrColoP01_129", "ClstrColoP01_130", "ClstrColoP01_131", 
"ClstrColoP01_132", "ClstrColoP01_133", "ClstrColoP01_134", "ClstrColoP01_135", 
"ClstrColoP01_136", "ClstrColoP01_137", "ClstrColoP01_138", "ClstrColoP01_139", 
"ClstrColoP01_140", "ClstrColoP01_141", "ClstrColoP01_142", "ClstrColoP01_143", 
"ClstrColoP01_144", "ClstrColoP01_145", "ClstrColoP01_146", "ClstrColoP01_147", 
"ClstrColoP01_148", "ClstrColoP01_149", "ClstrColoP01_150", "ClstrColoP01_151", 
"ClstrColoP01_152", "ClstrColoP01_153", "ClstrColoP01_154", "ClstrColoP01_155", 
"ClstrColoP01_156", "ClstrColoP01_157", "ClstrColoP01_158", "ClstrColoP01_159", 
"ClstrColoP01_160", "ClstrColoP01_161", "ClstrColoP01_162", "ClstrColoP01_163", 
"ClstrColoP01_164", "ClstrColoP01_165", "ClstrColoP01_166", "ClstrColoP01_167", 
"ClstrColoP01_168", "ClstrColoP01_169", "ClstrColoP01_170", "ClstrColoP01_171", 
"ClstrColoP01_172", "ClstrColoP01_173", "ClstrColoP01_174"), class = "factor"), 
    StartTime = c(40606.25061, 40613.33383, 40615.33381, 40616.00153, 
    40616.33428, 40616.41718, 40617.83499, 40619.33395, 40620.1675, 
    40620.1675, 40621.41763, 40621.50029, 40623.16725, 40626.41722, 
    40628.16791, 40629.25031, 40631.50061, 40634.00065, 40636.33382, 
    40637.25164, 40639.33382, 40645.33361, 40647.41722, 40650.41697, 
    40654.75097, 40662.25063, 40665.58383, 40672.16784, 40672.33392, 
    40673.50061, 40676.25063, 40679.33395, 40679.33395, 40682.58383, 
    40683.25063, 40683.25063, 40686.16729, 40687.16721, 40687.66826, 
    40689.16745, 40690.16769, 40690.16769, 40691.58397, 40694.1675, 
    40694.66792, 40697.41803, 40698.25054, 40701.8349, 40701.91763, 
    40701.91763, 40701.91763, 40704.50063, 40704.50063, 40706.5005, 
    40707.25153, 40709.16854, 40709.66792, 40711.0842, 40713.25049, 
    40715.33459, 40717.16815, 40717.83419, 40717.91738, 40720.16792, 
    40720.4177, 40721.08457, 40722.08534, 40723.25094, 40723.41721, 
    40725.16757, 40726.08416, 40726.41764, 40728.16756, 40731.00058, 
    40732.16718, 40733.50079, 40734.25069, 40734.83429, 40736.25082, 
    40737.33414, 40740.16718, 40740.33396, 40741.33417, 40742.58402, 
    40745.16764, 40747.25076, 40748.66868, 40751.16728, 40752.16801, 
    40755.33395, 40757.33396, 40758.25196, 40759.16733, 40760.25065, 
    40761.16715, 40763.25082, 40765.25122, 40766.08398, 40767.08502, 
    40770.25082, 40770.25082, 40773.16729, 40775.16729, 40775.3336, 
    40779.16737, 40780.75084, 40784.25118, 40785.16757, 40787.16787, 
    40788.41765, 40789.33449, 40789.41725, 40790.41747, 40793.33457, 
    40795.33396, 40796.08381, 40800.33484, 40805.25146, 40806.16756, 
    40806.33362, 40808.41763, 40808.66729, 40813.16731, 40814.0839, 
    40815.16728, 40816.2505, 40817.16715, 40818.25047, 40819.16706, 
    40821.08388, 40824.08396, 40828.33395, 40834.00063, 40835.25083, 
    40837.16714, 40837.25089, 40839.25096, 40841.58391, 40845.1678, 
    40846.25096, 40847.25049, 40848.00063, 40856.58451, 40863.41729, 
    40866.25061, 40866.41708, 40872.41741, 40874.41722, 40878.08443, 
    40878.33394, 40882.33451, 40886.3345, 40887.16882, 40890.08417, 
    40892.16723, 40893.16728, 40895.58416, 40899.25063, 40902.0009, 
    40902.25057, 40904.91693, 40913.16714, 40913.3336, 40915.08363, 
    40916.91749, 40917.6678, 40923.33388, 40924.25049, 40926.41731, 
    40942.08396, 40942.33416, 40942.33416, 40944.33398, 40948.25127
    ), EndTime = c(40610.66742, 40614.50083, 40615.50058, 40616.16792, 
    40617.00083, 40616.50061, 40619.08395, 40619.50057, 40622.00096, 
    40622.00096, 40622.50082, 40622.25047, 40624.50089, 40626.75049, 
    40628.41738, 40629.50126, 40633.33388, 40636.25096, 40636.41714, 
    40637.41885, 40640.1675, 40645.41728, 40650.33389, 40651.50074, 
    40659.25049, 40664.08417, 40670.41729, 40672.25049, 40673.16737, 
    40675.16719, 40678.41721, 40682.50057, 40683.08426, 40683.08426, 
    40685.41774, 40685.41774, 40686.25097, 40687.33382, 40688.41764, 
    40690.08403, 40692.33422, 40690.33396, 40693.41797, 40694.66792, 
    40697.25047, 40698.08381, 40700.08396, 40704.33433, 40704.33433, 
    40704.33433, 40704.33433, 40706.33497, 40706.33497, 40707.16714, 
    40709.08457, 40710.16715, 40710.83464, 40713.16823, 40714.75108, 
    40716.91745, 40717.66883, 40719.58429, 40718.91804, 40720.33463, 
    40720.66725, 40721.66832, 40723.00063, 40723.335, 40723.50125, 
    40726.00056, 40726.16757, 40726.58424, 40729.16729, 40732.00124, 
    40732.25049, 40734.08389, 40734.66764, 40735.75066, 40736.50166, 
    40738.25132, 40740.25057, 40740.41718, 40742.50058, 40744.41833, 
    40745.25073, 40747.41698, 40750.33404, 40751.41803, 40752.41844, 
    40755.41771, 40758.08388, 40758.33464, 40759.41819, 40760.41794, 
    40762.08395, 40764.16728, 40765.33381, 40766.33431, 40768.08451, 
    40772.50161, 40772.50161, 40773.41763, 40776.16721, 40777.00096, 
    40779.50131, 40782.08429, 40784.33466, 40785.50065, 40787.33396, 
    40788.50091, 40790.08448, 40790.08448, 40792.50072, 40794.41721, 
    40795.58455, 40798.50096, 40802.50058, 40807.25035, 40806.25083, 
    40806.41694, 40808.50064, 40812.25051, 40813.25141, 40814.16694, 
    40815.33431, 40816.33411, 40818.16694, 40818.41722, 40819.25057, 
    40823.50061, 40825.41715, 40828.41729, 40836.00071, 40835.50061, 
    40837.41722, 40837.33422, 40839.33383, 40845.00082, 40845.25083, 
    40846.33449, 40847.50049, 40852.50125, 40860.00057, 40865.41697, 
    40866.33396, 40871.50064, 40872.50091, 40874.5003, 40878.16729, 
    40878.75047, 40884.50059, 40886.50064, 40888.00076, 40891.08429, 
    40892.41729, 40895.50097, 40896.25063, 40900.08458, 40902.16728, 
    40904.50082, 40910.41728, 40914.7505, 40915.0005, 40915.16821, 
    40917.16722, 40918.58431, 40923.50047, 40924.41725, 40936.08396, 
    40942.25054, 40942.50049, 40942.50049, 40947.75089, 40958.66853
    )), .Names = c("ClstrID", "StartTime", "EndTime"), class = "data.frame", row.names = c(NA, 
-174L))

The head() and dim() are here.

head(two)
           ClstrID StartTime  EndTime
1 ClstrColoP01_001  40606.25 40610.67
2 ClstrColoP01_002  40613.33 40614.50
3 ClstrColoP01_003  40615.33 40615.50
4 ClstrColoP01_004  40616.00 40616.17
5 ClstrColoP01_006  40616.33 40617.00
6 ClstrColoP01_005  40616.42 40616.50


   dim(two)
    [1] 174   3

Notice there are many more serial DateTime’s in ‘one’ than in ‘two.’

When the single serial DateTime in object ‘one’ is between the Start and End serial DateTime of object ‘two’ I am trying to add the ClstrID of ‘two’ to ‘one.’ Said differently, every serial DateTime of ‘one’ should have the ClstrID of ‘two’ if between the Start and End interval. Note however, not all single DateTime numbers will fall within a Start and End number – many single numbers will be outside a time interval.

Also a few DateTimes from 'one' will fall in two different time intervals of 'two. ' My real data set is substantially longer and I am thus trying to build this into a for() loop or function() that checks if the ‘one’ serial number is between ANY (i.e. all rows) of the Start and End intervals of ’two’ and if yes, adds the corresponding ClstrID to the corresponding serial number in ‘one.’

Using code from John’s suggestions on my earlier post I can identify the single serial DateTime from ‘one’ that is between the two serial numbers of ‘two.’

clstrID.ch <- as.character(two$ClstrID)     #Make clstr ID a charater
f <- function(x){
    a <- clstrID.ch[ (two$StartTime <= x) & (x <= two$EndTime) ]
    if (length(a) == 0) NA else a
    }  
one$NewID <- lapply(one$DateTimeNumber, f)

but keep getting error messages regarding the uniqueness my breaks when I use the cut() function in the code below–

cut(one$DateTimeNumber, breaks = c(2, two$EndTime), 
    labels = two$ClstrID, include.lowest = TRUE, right = TRUE) 

The error is...

Error in cut.default(one$DateTimeNumber, breaks = c(2, two$EndTime), labels = two$ClstrID,
'breaks' are not unique

Obviously suggesting I have repeat DateTime serial numbers.

Any suggestions would be appreciated and help greatly.

Thanks.

Arun
  • 116,683
  • 26
  • 284
  • 387
B. Davis
  • 3,391
  • 5
  • 42
  • 78
  • Hello, is it possible to trim down this question into a more manageable chunk? – Ricardo Saporta Oct 11 '13 at 19:45
  • It would be better to provide a small sample of your data, directly in your question with `dput` for example, instead of the whole data file to download. – juba Oct 11 '13 at 19:47
  • This is a small data set sample relative to my entire data set. In a previous post used a mock dataset posted through 'dput.' I initially started small and have built up to this post. If need be i can trim this down however. – B. Davis Oct 11 '13 at 19:53
  • Yeah, I agree. This may be reproducible for now (I haven't installed RCurl yet), but if it could be read in directly from the question, then the question will (1) be easier for us to work with and (2) still remain relevant in the future when you or Google move or delete those links. Also, you could show us `head` and `dim` results, e.g., on lines starting with #. – Frank Oct 11 '13 at 21:47
  • I'm confused about how you get an error from `cut`. Your function `f` does not seem to be using it...I suspect that this command is not actually giving you the error: `lapply(one$DateTimeNumber, f)` – Frank Oct 11 '13 at 21:50
  • I have added the head() and dim () results. The struggle with a smaller data set is that it looses reliance to my actual task. As far as I have read, dput() is the bet way to add data directly to the question, although reliant data sets are rather large for that function. Are there other ways to get you data (the RCurl pkg is pretty slick...)? – B. Davis Oct 12 '13 at 00:03
  • 1
    You may also check [this way to post data](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/16532098#16532098). – Henrik Oct 12 '13 at 00:33
  • @Henrik, the post you suggested above sounds great although the example code results in "Error in reproduce(DF, cols = c("id", "X1", "X73", "Class")) : could not find function "is.data.table" when I run the reproduce() function. There is no comment section on that page to post. Any suggestions? I have the data.table pgk on my machine as well as devtools and Rtools. – B. Davis Oct 12 '13 at 02:34
  • 1
    Have you loaded `data.table` before you run `reproduce` on your `data.table` object? – Henrik Oct 12 '13 at 15:02
  • @Frank, John et al. I have made the data directly available through dput() if you are still interested and willing to offer assistance. Thanks! – B. Davis Oct 13 '13 at 21:59
  • Ok, having a look again and I ran across this: "checks if the ‘one’ serial number is between ANY (i.e. all rows) of the Start and End intervals of ’two’ and if yes, adds the corresponding ClstrID to the corresponding serial number in ‘one.’" It seems that there should be more than one "corresponding" ClstrID. Also, I realize that your first attempt at a minimal reproducible example didn't achieve your goal (since it used integers), but I think you would still have better luck constructing a small example from scratch than dropping a chunk of your real data... – Frank Oct 13 '13 at 22:19
  • Finally, "serial number" is confusing here. https://en.wikipedia.org/wiki/Serial_number – Frank Oct 13 '13 at 22:20
  • Also, @John's answer works just fine, so it's not clear why you are calling `cut`... – Frank Oct 13 '13 at 22:44

1 Answers1

1

You should not pass repeated values to the breaks= argument of cut. In this case, there are 10...

length(two$EndTime)
# [1] 174
length(unique(two$EndTime))
# [1] 164

Let's have a look:

badrows <- which(duplicated(two$EndTime))
# [1]  10  34  36  49  50  51  53 101 112 172
two$EndTime[badrows]
# some values

So, those are the repeating values. The vector is sorted, so the first instance of each of these shows up at...

badrows - 1
# [1]   9  33  35  48  49  50  52 100 111 171

The documentation for ?cut discusses how it should be used. Links to related functions are found at the bottom of that page. I think the high-level problem the OP wants to solve is covered by these.

Frank
  • 66,179
  • 8
  • 96
  • 180