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

RemoveDuplicates

This phrase should work in all APLs to remove all but the first of each unique item from a vector of any type.

      ((V⍳V)=⍳⍴V)/V                         ⍝ V←AV

Examples

      ⎕FX⍕2 1⍴'r←RemoveDuplicates av' 'r←((av⍳av)=⍳⍴av)/av'
      RemoveDuplicates,' ',⎕CR'RemoveDuplicates'
 r←RemovDuplicats(⍳)=⍴/
      RemoveDuplicates 0 1 0 1 2 1 0 1 2 3 2 1 0
0 1 2 3
      RemoveDuplicates'0 1 0 1 2 1 0 1 2 3 2 1 0'
0 123
      RemoveDuplicates'zero' 'one' 'zero' 'one' 'two' 'one' 'zero'
 zero  one  two
      RemoveDuplicates(0 1)(1 2)(0 1)(1 2)(2 3)(1 2)(0 1)
 0 1  1 2  2 3

Specialities

Dyalog and APLX

Dyalog and APLX have implemented the unique monadic function as a primitive.

Compatibility

CheckedWith: APL2, APLX, Dyalog, NARS2000

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←RemoveDuplicates av' 'r←((av⍳av)=⍳⍴av)/av'
⍝ ---- Start Test cases (do not delete this!)
 ' r←RemovDuplicats(⍳)=⍴/'≡RemoveDuplicates,' ',⎕CR'RemoveDuplicates'
 0 1 2 3≡RemoveDuplicates 0 1 0 1 2 1 0 1 2 3 2 1 0
 '0 123'≡RemoveDuplicates'0 1 0 1 2 1 0 1 2 3 2 1 0'
 'zero' 'one' 'two'≡RemoveDuplicates'zero' 'one' 'zero' 'one' 'two' 'one' 'zero'
 (0 1)(1 2)(2 3)≡RemoveDuplicates(0 1)(1 2)(0 1)(1 2)(2 3)(1 2)(0 1)

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: RemoveDuplicateRows and DeleteMultipleBlanks .

Mentor: PhilLast

Tags: <Duplicates> <DeleteDuplicates> <UniqueItems> <SelectUnique>


CategoryPhrasesAll - CategoryPhraseSelection

phrasebook/removeduplicates (last edited 2011-12-26 10:34:19 by KaiJaeger)