table

Methods

Method Reference: table.setxor

table: tbl = setxor (tblA, tblB)
table: tbl = setxor (tblA, tblB, setOrder)
table: [tbl, ixA, ixB] = setxor (…)

Exclusive OR of two tables by rows.

tbl = setxor (tblA, tblB) returns the set of rows that are present in either tblA or tblB but not in both, with duplicate rows removed. Both tables must have the same variable names, although not necessarily in the same order; tbl keeps the variable order of tblA. Rows are compared by their variable values only (row names are ignored), and by default tbl is sorted by those values.

tbl = setxor (tblA, tblB, setOrder) controls the ordering of tbl, either 'sorted' (default) or 'stable'.

[tbl, ixA, ixB] = setxor (…) also returns index vectors ixA and ixB such that tbl is the vertical concatenation of tblA(ixA,:) and tblB(ixB,:).

Source Code: table

Example: 1

setxor returns the symmetric difference: rows in exactly one of the two tables, but not in both. Row identity spans every variable, of any type.

 A = table ({'Li'; 'Diaz'; 'Brown'}, [38; 40; 49], ...
            categorical ({'NY'; 'CA'; 'MA'}), ...
            'VariableNames', {'Name', 'Age', 'State'})
A =
  3x3 table

      Name       Age    State    
    _________    ___    _____    

    {'Li'   }     38       NY    
    {'Diaz' }     40       CA    
    {'Brown'}     49       MA
 B = table ({'Diaz'; 'Brown'; 'Lee'}, [40; 49; 30], ...
            categorical ({'CA'; 'MA'; 'TX'}), ...
            'VariableNames', {'Name', 'Age', 'State'})
B =
  3x3 table

      Name       Age    State    
    _________    ___    _____    

    {'Diaz' }     40       CA    
    {'Brown'}     49       MA    
    {'Lee'  }     30       TX
 setxor (A, B)
ans =
  2x3 table

     Name      Age    State    
    _______    ___    _____    

    {'Lee'}     30       TX    
    {'Li' }     38       NY

Diaz and Brown, shared by both, drop out — leaving Li (from A) and Lee (from B).