Questions tagged [associations]

Questions on the associative data-structure introduced in Mathematica version 10.

Questions about the usage of Association (<|"key1"-> value1, ..|>) an associative data-structure introduced in Mathematica version 10.

Useful links

How to make use of Associations?

588 questions
27
votes
5 answers

How can a key be renamed in an Association?

Consider an example Association: assoc = <|"a" -> 1, "b" -> "x", "this_key_is_too_long_to_type" -> {1}|>; Suppose I want to replace "this_key_is_too_long_to_type" with "c". I can replace it by transforming into Normal land and back into Association…
ArgentoSapiens
  • 7,780
  • 1
  • 32
  • 49
18
votes
5 answers

How to "flatten" a nested Association?

For example, I have a nested association like this <|"fff" -> <|"2001" -> <|5040.` -> {"S20010037", "S20010038", "S20010039", "S20010040", "S20010041", "S20010042"}|>, "2005" -> <|4350.` -> {"S20050448", "S20050449"}, 3450.` ->…
matheorem
  • 17,132
  • 8
  • 45
  • 115
14
votes
1 answer

Fractional Keys in Associations

I got into an unfortunate situation, involving fractions that can get changed by evaluation, which occur as (part of) keys in my associations. I will probably steer far away from the entire situation, mostly because of the following quote. In this…
Jacob Akkerboom
  • 12,215
  • 45
  • 79
14
votes
1 answer

Reversing a GroupBy operation

Suppose that I have a this list of associations data = {<|"axis" -> x, "model" -> a, "p1" -> 1, "p2" -> 2|>, <|"axis" -> x, "model" -> b, "p1" -> 3, "p2" -> 4|>, <|"axis" -> y, "model" -> a, "p1" -> 5, "p2" -> 6|>, …
Gustavo Delfino
  • 8,348
  • 1
  • 28
  • 58
13
votes
3 answers

Is there an idiomatic way to determine whether an `Association` is a subset of another?

I would like a way to tell if every key-value pair of an Association is contained in another. For instance, f[<|c -> 1, d -> 2|>, <|a -> 1|>] should evaluate False, but f[<|a -> 1, d -> 2|>, <|a -> 1|>] should evaluate True. The functions SubsetQ or…
Patrick Stevens
  • 6,107
  • 1
  • 16
  • 42
13
votes
5 answers

Association of Associations : how to permute level 1 and level 2 keys?

I have a ragged Association of Association, say : assoc = Association[ "1" -> Association["a" -> "x", "b" -> "y"], "2" -> Association[ "b" -> "z", "c" -> "k"] ] I would like to transform it into a Association…
andre314
  • 18,474
  • 1
  • 36
  • 69
12
votes
1 answer

Assigning new value in association

I experienced a problem in changing values in an association and broke down the problem to the following: Given a list of association (here with one element): temp = {<|"name" -> "Peter", "Punkte" -> 10, "Gender" -> "nn"|>} then the following does…
mgamer
  • 5,593
  • 18
  • 26
12
votes
4 answers

How does MapThread work with Associations?

According to the documentation, MapThread works on Association objects. But it doesn't seem to evaluate the passed function. For example: MapThread[#1 + #2 &, {<|a -> 1, b -> 2|>, <|a -> 5, b -> 6|>}] returns: <|a -> (#1 + #2 &)[1, 5], b -> (#1 +…
Niki Estner
  • 36,101
  • 3
  • 92
  • 152
11
votes
3 answers

Move the outer key inward in an association

I have a list that looks like: {15000001-><|"Loss" -> 2.85396*10^8, "Exposure" -> 6.61052*10^10|>, 15000002 -> <|"Loss" -> 1.25297*10^8, "Exposure" -> 1.57863*10^11|>, 15000003 -> <|"Loss" -> 2.05979*10^8, "Exposure" -> 6.88024*10^10|>} I want to…
Mitchell Kaplan
  • 3,696
  • 22
  • 34
10
votes
1 answer

Find and return the key with lowest value in association list

I am still new in Mathematica, and I need some help here. Suppose that I have an association A=Association[1 -> 1, 2 -> 1, 3 -> 4, 4 -> 6, 5 -> 4, 6 -> 4, 7 -> 2, 8 -> 2, 9 -> 2, 10 -> 1, 11 -> 4, 12 -> 1, 13 -> 3, 14 -> 2, 15 -> 3, 16 -> 1] and I…
Kent Vk
  • 199
  • 7
9
votes
2 answers

JoinAcross on nested association by nested key

I would like to join two associations on nested keys. Is this possible? first = {<|"away" -> <|"name" -> "bob", "money" -> 10 |>, "home" -> <|"name" -> "Sue", "money" -> 15 |>|>, <|"away" -> <|"name" -> "Joe", "money" -> 20 |>, "home" -> <|"name"…
Ray Troy
  • 1,299
  • 7
  • 14
9
votes
2 answers

Ordered associations

Mathematica 10 has introduced Associations, elsewhere known as hash tables or dictionaries. Is there Ordered equivalent like in Python, Java, .NET? The data structure should remember the order in which key-value is…
den.run.ai
  • 972
  • 5
  • 16
9
votes
3 answers

Accesing keys based on position in an association

I would like to have the following simple function GetKey[] on a very large association. (* The actual Association is very large, this is just small example *) assoc = <|{1,1} -> 2, {1,2} -> 3, {2,1}->4, {2,2}->5|>; GetKey[assoc, 1] GetKey[assoc,…
Iconoclast
  • 503
  • 2
  • 9
8
votes
2 answers

Replace Missing[Unmatched] with zero

After a left JoinAcross, I have a number of Missing["Unmatched"] values in my list of associations. I'd like to set them all equal to zero. I tried the following: q = JoinAcross[Normal[reported], Normal[estimates], Key["key"], "Left"]; q1 = q /.…
Mitchell Kaplan
  • 3,696
  • 22
  • 34
8
votes
2 answers

Deleting all keys that have null values

I have a notebook that I am working on that starts with an imported CSV file. Many of the rows have blank data in them. I have used the following command to establish a list of associations: test = AssociationThread[First[rawdata] -> #] & /@…
kickert
  • 1,820
  • 8
  • 22
1
2 3 4 5 6