0
|
13134 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
GROUPS:

# [?] Join data with Dates?

Posted 6 years ago
 Dear All, I got a simple question. How to join data from two different files with the same Dates? Data1 = { {{2006, 01, 01}, 27}, {{2006, 01, 02}, 25}, {{2006, 01, 03}, 86}, {{2006, 01, 04}, 72}, {{2006, 01, 05}, 66}, {{2006, 01, 06}, 25}, {{2006, 01, 07}, 13} }; Data2 = { {{2006, 01, 01}, 33}, {{2006, 01, 02}, 36}, {{2006, 01, 03}, 100}, {{2006, 01, 04}, 100}, {{2006, 01, 05}, 76}, {{2006, 01, 06}, 100}, {{2006, 01, 07}, 27}};  This should be the outcome: HowToJoinData1withData2 = {{{2006, 01, 01}, 27, 33}, {{2006, 01, 02}, 25, 36}, {{2006, 01, 03}, 86, 100}, {{2006, 01, 04}, 72, 100}, {{2006, 01, 05}, 66, 76}, {{2006, 01, 06}, 25, 100}, {{2006, 01, 07}, 13, 27}};  Please can you help? Regards,.....Jos
5 Replies
Sort By:
Posted 6 years ago
 The (N+1)th solution: {#[[1, 1]], Sequence @@ #[[All, 2]]} & /@ GatherBy[data1~Join~data2, First] 
Posted 6 years ago
 To All,Thanks for your quick reply and excellent support. This was actually what I am looking for !Best Regards,....Jos
Posted 6 years ago
 Normal[GroupBy[Join[data1, data2], First -> Last, Sequence @@ # &]] /. {Rule -> List} SplitBy[Sort[Join[data1, data2]], First] /. z : {{_List, _Integer} ..} :> {First[First[z]], Sequence @@ z[[All, 2]]} lots of ways ;-)
Posted 6 years ago
 Please try Map[Function[FlattenAt[#, 2]], ReplaceAll[ Normal[Merge[ Map[Function[Association[Rule[#[[1]] , #[[2]]]]], Join[Data1, Data2]], Identity]] , RuleDelayed[Rule, List]] ] If your data fits this pattern {date, value} if it is {date,values,...} then change Rule[#[[1]],#[[2]]] to Rule[First[#],Rest[#]] and modify the rest of the code accordingly to get the final list into the form you desire.
Posted 6 years ago
 You could try: Merge[{Rule@@@Data1,Rule@@@Data2},Identity] List@@@Normal[%] Prepend[#2,#1]&@@@%