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}, ...}

marked as duplicate by Mr.Wizard Jun 30 '13 at 13:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Have a look at Gather or GatherBy, it might do most of the job. $\endgroup$ – b.gates.you.know.what Jun 30 '13 at 8:16
  • $\begingroup$ I am marking this as "already answered" because I believe it is. Also see: (20040) $\endgroup$ – Mr.Wizard Jun 30 '13 at 13:37

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}}


Not the answer you're looking for? Browse other questions tagged or ask your own question.