I needed to look at the changes in the values of about 4000 items from one year to the next. I have a table with identifiers and values for each year. Not all of the items are in each list. The tables contain the following rows, with more data to the right.
So I did the following:
govnew = Select[data[[2 ;;, {2, 3, 4, 6}]], #[[4]] > 0 &];
govold = Select[dataold[[2 ;;, {2, 3, 4, 6}]], #[[4]] > 0 &];
intersection = Intersection[govnew[[All, 1]], govold[[All, 1]]];
Clear[both];
Map[(both[#] = 1) &, intersection];
govnew2 = Select[govnew, both[#[[1]]] == 1 &];
govold2 = Select[govold, both[#[[1]]] == 1 &];
Which reduced the two lists to the intersection of the identifiers in both lists. It worked. But it reduces a list of Down Values to a dictionary. Doesn't use a Mathematica function in a secret and powerful way. Is there a more Mathematica like approach.
Scan
is more typical and cleaner instead of yourMap
above. $\endgroup${data, dataold} = List @@ RandomInteger[12, {2, 20, 6}];
$\endgroup$DownValues
. An alternative might be to join the lists, thenGatherBy[combinedlist,First]
or something along those lines. Now discard all singletons. $\endgroup$