I have two lists of time series data. One of the lists is daily and is formatted like this;
daily={{{2011, 7, 1, 6, 0, 0.}, 284606., 16735.3}, {{2011, 7, 2, 6, 0, 0.},
285283., 16669.9}, {{2011, 7, 3, 6, 0, 0.}, 287529., 16445.5}}
And another list which is hourly;
hourly={{{2011, 7, 1, 6, 0, 0.}, {3, 861, "", 2 ""}}, {{2011, 7, 1, 7, 0,
0.}, {3, 270, "", 2 ""}}, {{2011, 7, 1, 8, 0, 0.}, {3, "", "",2 ""}}}
I would like to merge the two list so the two values in the daily list repeat in the corresponding hourly list.
For the data given the result would look like this;
merged={{{2011, 7, 1, 6, 0, 0.},3, 861, "", 2 "", 284606., 16735.3},
{{2011, 7, 1, 7, 0,0.}, 3, 270, "", 2 "", 284606., 16735.3},
{{2011, 7, 1, 8, 0, 0.}, 3, "", "",2 "", 284606., 16735.3}}}
I would like to match the two sets by the year-month-day data. The time part of the daily data can be ignored.
I ended up coding a for loop that iterated through both lists to do the merge (after several attempts at doing this in a more elegant way). What I'm looking for is the proper way to do this in Mathematica, not a For loop that I could have done in C.
Any help would be greatly appreciated.
hourly
seems a little different... is the second element a list unlike for the daily data? In any case, lookupJoin
andGatherBy
(I seem to remember a similar question) $\endgroup$Function[x, (Append[{#[[1]], Sequence @@ #[[2]]} &@x, Hold@Sequence @@ Select[daily, #[[1, 1 ;; 3]] == x[[1, 1 ;; 3]] &][[1, 2 ;; 3]]])] /@ hourly // ReleaseHold
- but there are surely smarter/faster ways $\endgroup$