Investment Studio > Expressions > Functions > Matrix > SYNC
array[*][*] sync(array[*][*] a, array[*][*] b, keep_unmatched = TRUE)
Returns the two-dimensional array a, extended with entries from the two-dimensional array b.
For each row in a, a match to the value in its first column is sought in the first column of b. If a matching, previously unused row is found, its first (redundant) column is discarded and the remaining columns are appended to those from a.
If keep_unmatched is TRUE, unmatched rows from a are left in place (padded with empty columns to make up for missing elements from b) and rows from b which do not match any row in a are appended at the end of the result array, with empty columns inserted after the first one so as to line up with the rest of the result array.
If keep_unmatched is FALSE, unmatched rows from both a and b are discarded.
Examples
Given the arrays
_a = {{1, PI, "Hello"}, {2, "Goodbye", E}, {TRUE, 10, "OK"}, {FALSE, 20, "KO"}}
and
_b = {{FALSE, TRUE}, {1, " world"}, {"No match", "No fire"}}
the expression
=sync(array(_a), array(_b))
returns {{1, PI, "Hello", " world"}, {2, "Goodbye", E, }, {TRUE, 10, "OK", }, {FALSE, 20, "KO", TRUE}, {"No match", , , "No fire"}}.
The first row in the result is a match between row 1 in _a and row 2 in _b; result rows 2 and 3 are unmatched rows from _a (padded with empty columns to keep the result array rectangular); result row 4 is a match between row 4 in _a and row 1 in _b; and result row 5 is the remaining, unmatched row from _b, with empty columns inserted so as to line up with the rest of the result array.
With the same argument arrays, the expression
=sync(array(_a), array(_b), FALSE)
returns {{1, PI, "Hello", " world"}, {FALSE, 20, "KO", TRUE}}.
See also flipcols, fliprows, msort, swapcols, swaprows, transpose.