I've been trying to separate large segments of DateList formatted data (years worth at a time) into individual days using the Split
function.
The data has the form:
data = {{{y,m,d,h,m,s}, 154},{{y,m,d,h,m,s}, 157},...}
and unfortunately there is not a uniform length of data per day (or I would have just partitioned it). This is what I've been trying (or variations of it):
splitData = Split[data,#2[[1,3]]>#1[[1,3]]&];
or
splitData = Split[data,Less[#1[[1,3]],#2[[1,3]]]];
and plenty of other versions, but it doesn't split where I need it to.
I thought if I compared the days in the DateList slot the data would split (as days of a month are increasing until the new month begins.
My current solution (which is very inefficient) pulls the dates out of data and applies Union
, Union@data[[All,1]]
, then iterates through each data point comparing dates using nested tables. ... I know, a very poor method.
Anyone see how to us Split
or another more efficient method to separate?
If you need test data to work with I've been using this instead of the real data (a much smaller set):
dpmo[month_, year_] := DateDifference[{year, month, 1}, {If[month == 12, year + 1, year], If[month == 12, 1, month + 1], 1}];
dates = Flatten[Table[Table[{2012, month, day, 0, 0, 0}, {day, 1, dpmo[month, 2012]}], {month, 1, 12}], 1];
data = Flatten[Table[Table[{dates[[m]], RandomInteger[{100, 250}]}, {100}], {m, 1, Length@dates}], 1];
The code generates the equivalent to a years worth of data, however there is a definitive set of data per day (100) which I do not have in the actual set. I didn't feel like adding that to the test data.