Naming Conventions

Scalar

Vector

Matrix

Any
rank

Non-
scalar

Boolean

BS

BV

BM

BA

BN

Integer

IS

IV

IM

IA

IN

Float

FS

FV

FM

FA

FN

Numeric

NS

NV

NM

NA

NN

Character

CS

CV

CM

CA

CN

Enclosed
vector

ES

EV

EM

EA

EN

enclosed
Text vector

TS

TV

TM

TA

TN

Simple

SS

SV

SM

SA

SN

Any

AS

AV

AM

AA

AN

phrase e.g.: .X...Y. ⍝ X←BS; Y←IV

combinations: use ISV for Integer scalarvector

B3, I4 &c. to specify higher ranks.

Open full technical reference

RemoveDuplicateRows

Matrices can have duplicate rows which often have to be removed. The following phrase is universal for a simple matrix.

      (∨⌿<\SM∧.=⍉SM)⌿SM

Examples

      ⎕FX⍕2 1⍴'r←RemoveDuplicateRows sm' 'r←(∨⌿<\sm∧.=⍉sm)⌿sm'
      cm←7 4⍴'zero','one ','zero','one ','two ','one ','zero'
      RemoveDuplicateRows cm
zero
one
two
      RemoveDuplicateRows 0⌿cm   ⍝ no rows
      im←7 2⍴0 1,1 2,0 1,1 2,2 3,1 2,0 1
      RemoveDuplicateRows 0/im   ⍝ one empty row

      RemoveDuplicateRows im
0 1
1 2
2 3

Specialities

Dyalog

This succinct and more general version (it works on matrices of any depth) which reads "reassemble into a matrix the unique elements of the nested vector formed from the rows of the original" is dependent upon the implementation of monadic as mix, as unique, as split and ⎕ML≤1.

     ↑∪↓am

APLX and Dyalog

This version uses the more standard (and verbose) ⊂[1] as enclose with axis with ⎕IO=0 and as mix (requiring ⎕ML>1 in Dyalog).

      ⊃∪⊂[1]am

To remove the ⎕IO dependency substitute 0⊥⍳2 for the axis.

Compatibility

CheckedWith: APL2, Dyalog, APLX

Test Cases

Show test cases

Test
 ⎕IO←0      ⍝ You may change this; however, zero IS the default in the Phrasebook
⍝⎕ML←3      ⍝ Enable this line in Dyalog APL if appropriate
 ⎕FX⍕2 1⍴'r←RemoveDuplicateRows sm' 'r←(∨⌿<\sm∧.=⍉sm)⌿sm'
⍝ ---- Start Test cases (do not delete this!)
 cm←7 4⍴'zero','one ','zero','one ','two ','one ','zero'
 (3 4⍴'zeroone two ')≡RemoveDuplicateRows cm
 (0 4⍴' ')≡RemoveDuplicateRows 0⌿cm   ⍝ no rows
 im←7 2⍴0 1,1 2,0 1,1 2,2 3,1 2,0 1
 (1 0⍴0)≡RemoveDuplicateRows 0/im     ⍝ one empty row
 (3 2⍴0 1 1 2 2 3)≡RemoveDuplicateRows im

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: RemoveDuplicates

Mentor: PhilLast

Tags: <DeleteDuplicates> <DupRowsOut> <SelectUniqueRows>


CategoryPhrasesAll - CategoryPhraseCharacterManipulation - CategoryPhraseSelection

PhraseBook/RemoveDuplicateRows (last edited 2011-12-26 10:34:32 by KaiJaeger)