Mathematica: Associations

  


Associations and Parts:

 

  • <| ... |> [["str"]] -- extract a value corresponding to a key that is a string
  • Key -- indicate a key within a part specification
  • Missing -- default value if a key is not found
  • #name -- a slot in a prue function that picks out value with key "name" in an association
  • AssociationQ -- test if an expression is a valid association
     

 

Elements of Associations:

  • Keys — list of keys
  • Values — list of values
  • Normal — convert to a list of rules
  • Lookup — perform a lookup of a value by key, returning a specified default if it is not found
  • KeyExistsQ — test whether a key exists in an association
     

Functions That Apply to Values:

  • KeySortKeySortBy — sort an association by its keys
  • KeyTakeKeyDrop — take, drop particular keys in an association
  • KeySelect — select elements based on a criterion on their keys
  • KeyMap — map a function over the keys in an association
  • KeyValueMap — map a function over keys and values in an association
    • KeyMemberQ
    • KeyFreeQ
       

Modifying Associations:

  • <|…|>[key]=val — change an element of an association
  • AssociateTo — add elements to an association
  • KeyDropFrom — drop elements from an association
     

Pattern Matching with Associations:

  • KeyValuePattern — elements that can appear anywhere in an association
     

Functions That Create Associations:

  • Association — turn a list of rules into an association
  • AssociationMap — create an association by applying a function to a list of keys
  • AssociationThread — create an association from a list of keys and a list of values
  • CountsCountsBy — associate values with the number of times they occur
  • GroupBy — group values by collecting those sharing a criterion ("map reduce")
  • PositionIndex — build an index of positions at which values occur
     

Functions Operating on List of Associations:

  • KeyUnion
  • KeyIntersection
  • KeyComplement
  • Catenate — catenate elements from multiple associations
  • Merge — merge associations using a function to combine elements with common keys
  • JoinAcross — do the analog of a database join on multiple associations
  • Dataset — representation supporting general structured data queries

 

Referenced from: Mathematica

19593
12/21/2017 2:11:33 PM