Key

From APL Wiki
Revision as of 08:31, 16 January 2022 by Adám Brudzewsky (talk | contribs) (wp link)
Jump to navigation Jump to search

Key () is a primitive monadic operator which takes a dyadic function operand where specified keys group the indices or major cells of an argument. It was introduced in Dyalog APL version 14.0 and is commonly compared to SQL's GROUP BY statement.

Contents

Description

Monadically, key will group identical major cells together and applies the function operand f to each unique key, and the indices of the elements matching that key.

      {⍺⍵}'Mississippi'
┌─┬────────┐
M1       
├─┼────────┤
i2 5 8 11
├─┼────────┤
s3 4 6 7 
├─┼────────┤
p9 10    
└─┴────────┘

In the dyadic case, key applies f to the elements of the right argument corresponding to the unique elements of the left.

      'Mississippi'{⍺⍵}'ABCDEFGHIJK' 
┌─┬────┐
MA   
├─┼────┤
iBEHK
├─┼────┤
sCDFG
├─┼────┤
pIJ  
└─┴────┘

In fact, the monadic case f is equivalent to f ⍳≢

External links

Lessons

Documentation


APL built-ins [edit]
Primitive functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Name classCase convertUnicode convert
Operators SearchReplace