Skip to content

differ

Find where list items change value

differ x    differ[x]

Returns a boolean list indicating where consecutive pairs of items in x differ. It applies to all data types.

differ is a uniform function. The first item of the result is always 1b.

    r[i]=1b                 for i=0
    r[i]=not A[i]~A[i-1]    otherwise
q)differ`IBM`IBM`MSFT`CSCO`CSCO
10110b
q)differ 1 3 3 4 5 6 6
1101110b
q)differ (7;`a;`a;09:34)
1101b

Tip

Combine with Cut (_) to split a table with multiple dates into a list of tables with distinct dates.

q)t:([]date:2009.10.01 2009.10.01 2009.10.02 2009.10.02 2009.10.02;sym:`IBM`CSCO`MSFT`CSCO`IBM;price:37.95 52.91 18.90 12.75 33.10;size:710 594 26 760 300)
q)i:where differ t`date      / indices where dates differ
q)i
0 2
q)tlist:i _ t                / list of tables with one date per table
q)tlist 0
date       sym  price size
--------------------------
2009.10.01 IBM  37.95 710
2009.10.01 CSCO 52.91 594
q)tlist 1
date       sym  price size
--------------------------
2009.10.02 MSFT 18.9  26
2009.10.02 CSCO 12.75 760
2009.10.02 IBM  33.1  300
domain: B G X H I J E F C S P M D Z N U V T
range:  B B B B B B B B B B B B B B B B B B

differ is a multithreaded primitive.

Binary use deprecated

Binary application is deprecated and might disappear in future versions. The keyword cannot be applied infix.

For a binary version, use Match Each Prior: ~:'.


Comparison