Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}, ...}
share|improve this question

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  
Have a look at Gather or GatherBy, it might do most of the job. –  b.gatessucks Jun 30 '13 at 8:16
    
I am marking this as "already answered" because I believe it is. Also see: (20040) –  Mr.Wizard Jun 30 '13 at 13:37

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer

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