Take a ragged 2D array:
rArray={{4, 2, 1, 0}, {2, 2}, {0, 0, 3, 3, 3}, {4, 0}, {3, 4}}
I need to "deduplicate" this, where a duplicate is any element of a sublist where that element exists at the same position in a prior sublist, e.g., on the above example, the result would be
{{4, 2, 1, 0}, {2}, {0, 0, 3, 3, 3}, {}, {3, 4}}
Targets are numeric (integer, in fact).
I'm using the following:
keepFirst[lst_List] := Module[{u = Unique[], t},
t = Flatten[PadRight[lst, Automatic, u], {{2}, {1}}];
t = Block[{f}, f[a_] := (f[a] = u; a); Map[f, #]] & /@ t;
DeleteCases[Flatten[t, {{2}, {1}}], u, {2}]];
Does what I need, reasonably quick, wondering if there's perhaps a cleaner/more efficient means.
(N.b: Above fn is output from a function I use to generate these for differing dimensions/etc. - in the 2D case, Flatten[...,{{2},{1}}] can obviously simplify to the slightly faster Transpose@... with minor speed increase.)
RandomInteger[100000, #] & /@ RandomInteger[{1, 10}, 100000]. +1 – ciao Aug 09 '15 at 22:14