I have two lists of data including dates such as
data1 = {{{yy, mm, dd}, a}, ...}
data2 = {{{yy, mm, dd}, A}, ...}
There are some missing dates from each list, but I want to have the data which are only available in both lists and combine them like this:
data3 = {{{yy ,mm, dd}, a, A}, ...}
Answer
This follows b.gatessucks suggestion.
First, some data. data1
has 10 items; data2
has 7 items, each of which was collected on the same date as its counterpart in data1
.
data1 = Table[{{2010, 12, k}, a}, {k, 10}]
data2 = Drop[data1, {4, 7}] /. a -> A
Then join and process. (I'm assuming there data1
, data2
each have at most no more than one piece of data for a given date. ) Cases
selects data pairs having the same date and returns the information in the desired format.
Cases[GatherBy[Join[data1, data2], First], {{w_, x_}, {w_, z_}} :> {w, x, z}]
{{{2010, 12, 1}, a, A}, {{2010, 12, 2}, a, A}, {{2010, 12, 3}, a, A}, {{2010, 12, 8}, a, A}, {{2010, 12, 9}, a, A}, {{2010, 12, 10}, a, A}}
Comments
Post a Comment