Key: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(operand has to be dyadic)
(wp link)
Line 1: Line 1:
{{Built-in|Key|⌸}} is a [[primitive operator|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" clause.
{{Built-in|Key|⌸}} is a [[primitive operator|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 [[wikipedia:Group by (SQL)|GROUP BY]] statement.


== Description ==
== Description ==

Revision as of 08:31, 16 January 2022

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.

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'
┌─┬────────┐
│M│1       │
├─┼────────┤
│i│2 5 8 11│
├─┼────────┤
│s│3 4 6 7 │
├─┼────────┤
│p│9 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' 
┌─┬────┐
│M│A   │
├─┼────┤
│i│BEHK│
├─┼────┤
│s│CDFG│
├─┼────┤
│p│IJ  │
└─┴────┘

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

External links

Lessons

Documentation


APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector