We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [associations]

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

Filter by
Sorted by
Tagged with
145
votes
3answers
10k views

How to make use of Associations?

I have been curious about it for long. Now that Mathematica 10 arrives, I think it's time to ask the question: How the new Association data structure would be used ...
50
votes
3answers
4k views

Changing Values in an Association using Map

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as: ...
40
votes
2answers
2k views

Dataset vs an association of associations

Associations with a record structure (e.g., a flat table) can be organised in one of two main ways. First as a list of associations, which is also used in the case of Mathematica's data set ...
19
votes
3answers
2k views

Converting hierarchies of rules to associations

The impossibility of MatchQ-ing inside and Association MatchQ-ing Associations (MMA 10) explains a problem I have. I would like ...
20
votes
2answers
696 views

MatchQ-ing Associations (MMA 10)

Consider {x->1} which has FullForm List[Rule[x, 1]] and, therefore, ...
61
votes
6answers
9k views

How can I add a column into a existing Dataset?

I'm very excited about the brand new Dataset function. I have played with it in Wolfram Cloud, and haven't figured out how can I add a new column into an existing <...
7
votes
1answer
720 views

Is there a faster way to Map an Association?

Consider mapping an existing Association in a manner such as this: ...
32
votes
4answers
867 views

How to organically merge nested associations?

Suppose I want to construct an association of associations, such as a list of people with attributes: ...
11
votes
2answers
407 views

Held keys in associations

Bug introduced in 10.0 and persisting through 11.0.1 or later Bug introduced in 10.0 and fixed in 10.4 Association is new in 10.0. Bug still present: ...
18
votes
2answers
308 views

Association's Attributes change between 10.3.1 & 10.4?

In Mathematica 10.3.1 In[1]:= Attributes[Association] Out[1]= {Protected} In Mathematica 10.4: ...
8
votes
3answers
513 views

GroupBy a list of associations with their keys

How can I go from ...
12
votes
2answers
347 views

Pattern matching Association in rules

I would appreciate an explanation of how Associations behave in pattern matching, especially when matching rules, and using HoldPattern. Consider the following: ...
9
votes
5answers
2k views

How to switch from List of rules to Association? [duplicate]

Considering we have a list of rules: ...
16
votes
1answer
271 views

Pattern matching to a function evaluation inside an Association

I find the following behaviour deeply counter-intuitive: <|1 -> 123.456 |> /. {x_?NumericQ -> Round[x]} (* <|1 -> Round[123.456]|> *) That ...
21
votes
2answers
889 views

Difference between Association and Dispatch

In the example below, Association has a different behavior from Dispatch: ...
10
votes
1answer
205 views

Different Set Semantics - Why is assoc[“a”] =. different from assoc[[“a”]] =.?

Accessing parts of an Association can be done either using Part or the [] extraction ...
9
votes
4answers
329 views

Create Nested List from tabular data

Im trying to create a nested list from tabular data, then onward into a nested association. I can get part way with the help of this answer but it only works for the first level. Repeated use of this ...
15
votes
6answers
678 views

Reshaping associations, generalization of GroupBy

Let's say we have a set a\of associations: ...
9
votes
4answers
424 views

Pattern match for nested Association

Suppose I have Association testAssoc=Association[a->Association[1->1,2->2],b->Association[1->1,2->2]] which ...
7
votes
1answer
156 views

Problem Using Evaluated Replace with Associations

If I define some function like: toISOdate[data_List]:=DateString[data,{"Year","-","Month","-","Day"}] and try to applicate it in an ...
11
votes
2answers
217 views

Lookup with default broken in Dataset

Given an Association, ...
5
votes
1answer
307 views

Immutability, Association and typing

I have read the article by Leonid on the question. I am still struggling. I am trying to use Association to inject some pseudo-typing in my code. Here is my ...
3
votes
1answer
188 views

Using Associations and Pattern matching in numerical functions possibly broken

It looks like the very young feature of pattern matching (/replacing) within Associations (https://mathematica.stackexchange.com/a/119542/6804), with or without ...
13
votes
1answer
376 views

10.0.2 mapping Association to Dataset warning

Bug introduced in 10.0.2 and fixed in 10.0.3 In 10.0.2 ExampleData[{"Dataset", "Titanic"}][All, <| "gender" -> #sex|> &] Outputs the expected ...
18
votes
3answers
1k views

Assign names to Dataset columns

I am constructing a dataset like so: data = Dataset[AssociationThread[Keys[characterCounts], charFrequencies]] which gives me a dataset that looks like this: ...
16
votes
2answers
297 views

Listable functions thread over Associations; is this documented?

Thanks to a somewhat misapplied use of MapThread I learned of this behavior: ...
16
votes
2answers
967 views

Change Values in Dataset under Condition

I have the following Dataset: ...
13
votes
3answers
369 views

Dataset collapsing/reducing

I have a dataset ds with 3 columns named A, B, C. Columns A and B have repeated values. How can I obtain another dataset that contains a list of the values in C for ...
11
votes
2answers
237 views

Missing: KeyGroupBy?

Especially in tree-structured data, keys and values, being two sides of the same coin, frequently interchange roles. The ability to aggregate by value but not by key upsets the balance. How to ...
15
votes
2answers
395 views

AssociationMap loses definition

Bug introduced in 10.0.0 and fixed in 10.1.0. I'm facing a strange behavior of AssociationMap. With a fresh Kernel session: ...
13
votes
2answers
346 views

Replace and Association

I'm surprised that I can't find this question already, so perhaps I'm missing something obvious. I would like to take a list of associations and remove any with value ...
9
votes
2answers
294 views

Passing an unevaluated part of an association to a function

I'm making a UI widget that controls sound volume on a speaker using a slider, e.g.: ...
4
votes
1answer
645 views

Using Datasets in Mathematica 10.0

Bug introduced in 10.0 and fixed in 10.1 I am trying to use the Dataset functionality which was introduced in Mathematica 10.0 : ...
7
votes
2answers
225 views

Allocate amount A according to the distribution of amount B

I have a cost that varies by category and date. I also have the counts of each item type within each category and date. I want to distribute the cost to each of the item types. I'm trying to use <...
1
vote
2answers
237 views

Creating Association [duplicate]

I have provided a dataset bellow and I would like to store the data as an Association that I can query. Such that e.g. ...
19
votes
1answer
755 views

Learning Resources for Data Science in the Wolfram Language

I'm delivering an upcoming course on Data Science with the programming/analysis done predominantly in the Wolfram Language. I created the following table to leverage students' familiarity with Lists ...
25
votes
3answers
1k views

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}|>; ...
11
votes
1answer
195 views

Nested association values validation. POJsO handling

Sometimes it is convenient to work in your package/app with "objects" like: ...
17
votes
7answers
1k views

How to search Dataset to find all keys share same Value

If I have the following Dataset ...
12
votes
0answers
170 views

Unix-like reference to parent and root Association?

Is there a syntax or function to reference parent and root when querying nested Associations similar to Unix' ".." and "/", eg "cd ../../mydir". ? Here's a typical application of the root construct....
7
votes
3answers
941 views

Normal // Association // Dataset workaround for some user query operators

Given example tabular data (ie, with rows and columns, or "data frames") ...
12
votes
1answer
146 views

Unexpected behavior of KeyTake

list = {{a, b, c, e}, {1, 2, b, h}, {"a", "h", 3, 5}}; asso = GroupBy[list, {#[[1]], #[[2]]} &] ...
11
votes
1answer
285 views

10.0.2 breaks a recursive “trie” query

Bug introduced in 10.0.2 and fixed in 10.2 The 10.0.2 Dataset type system complication breaks a recursive trie constructor that worked in 0.1: ...
9
votes
0answers
309 views

Dataset: cannot reproduce a basic example. A bug? [duplicate]

Just to report: I try to reproduce the very first example for the Dataset from the Documentation Center: ...
9
votes
3answers
286 views

Problem constructing Association tables with some operators

fixed in 10.0.2 First, set up the example Dataset from the documentation: titanic = ExampleData[{"Dataset", "Titanic"}]; Why ...
7
votes
1answer
231 views

How does thing[“property”] syntax work?

Many builtin "things" support the (usually undocumented) syntax thing["property"], and usually the available properties can be listed using thing["Properties"] (thing["Methods"] might work too). ...
6
votes
2answers
203 views

DeleteMissing level spec confusion

Given: titanic = ExampleData[{"Dataset", "Titanic"}] Why does this correctly delete Missing[] elements: ...
5
votes
1answer
409 views

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 ...
9
votes
1answer
193 views

Applying functions to irregularly distributed Keys in Association lists

This Q is related to this one, but now refer to the situation as irregularly distributed Keys in lists of Associations: ...
8
votes
4answers
416 views

Extract all Values from nested Association

Considering we have an Association: ...