59 votes
Accepted

Changing Values in an Association using Map

Preamble This is a very good question, because answering it will make it very clear what immutability means, both in general and in the context of Associations. ...
52 votes

Dataset vs an association of associations

A Dataset represents an abstraction over a structured collection of data. Notionally, it is restricted to "well-behaved" data -- data that comes in simple forms ...
  • 67.5k
34 votes

How can I add a column into a existing Dataset?

Another way that works (for one or more columns) is: ds[All, <|#, "col3" -> #col1 + #col2, "col4" -> #col1 - #col2|> &] This gives: Also, ...
  • 1,126
32 votes

Changing Values in an Association using Map

I hesitate to add anything after @Leonid's comprehensive answer, but I'd like to point out that an easy way to achieve the stated goal is to define f like this: <...
  • 67.5k
32 votes
Accepted

How to organically merge nested associations?

Initial data: ...
  • 133k
29 votes

Converting hierarchies of rules to associations

There is a ToAssociations function in the GeneralUtilities` package that is perfect for this and for converting nested JSON ...
  • 87.2k
28 votes
Accepted

Difference between Association and Dispatch

General If you are not going to change your list of rules after you construct them, Dispatch is pretty good. From the user's viewpoint, the main difference is that ...
28 votes
Accepted

Assign names to Dataset columns

data = N @ Normalize[#, Total] & @ Counts @ Characters @ ExampleData[ {"Text", "DeclarationOfIndependence"} ]; Dataset @ data ...
  • 133k
27 votes

Difference between HashTable datastructure and Association datastructure

Summary Important differences between Association and CreateDataStructure["HashTable"] include: associations are ...
  • 67.5k
24 votes
Accepted

What's the difference between these 2 associations?

Preamble The real problem here seems somewhat deeper than what the (mostly correct) observations in comments indicate. In Mathematica, a number of objects, which are so-called raw objects (including ...
22 votes

Reverse Lookup: getting keys from values

PositionIndex[assoc][<value>] For example: ...
  • 10.6k
22 votes
Accepted

Count works differently depending on how an association was created

As Kirill Belov notes in a comment, the issue is related to the fact that the list a1 is a packed array (generated by Range) ...
  • 67.5k
21 votes

Assign names to Dataset columns

Actully we have a easiest way,suppose you have dataset like ...
  • 24.6k
21 votes
Accepted

Is it possible to avoid unpacking when merging Association?

One can use TracePrint to see how Flatten is being used by Merge: ...
  • 125k
19 votes
Accepted

MatchQ-ing Associations (MMA 10)

Association is atomic: <|x -> 1|> // AtomQ True Therefore standard pattern ...
  • 265k
19 votes

How can a key be renamed in an Association?

Somewhat similar to the answer of evanb, but without explicit mutations: ...
19 votes

Bug with Block & Lookup: Scope Variable Leak

Looks like a bug to me as well. Just as Michael I would suspect that the problem is more with Lookup than Block or ...
  • 23.2k
18 votes

How to switch from List of rules to Association?

The undocumented function ToAssociations in the GeneralUtilities package does this ...
  • 3,326
18 votes
Accepted

Why do lookup times in Dataset and Association differ by orders of magnitude?

As @Mr.Wizard notes in a comment, some discussion about the overheads associated with querying can be found in another question (56609). This response will use Mathematica version 10.1.0 to examine ...
  • 67.5k
18 votes

Merge function performing too slowly; what can be done about it?

It appears GroupBy does not suffer from this performance issue, so here is an alternative implementation using it, compared to ...
  • 265k
17 votes

Reverse Lookup: getting keys from values

One way would be to "invert" the association and then look up values in the result: ...
  • 67.5k
16 votes
Accepted

How can a key be renamed in an Association?

There is, of course: ...
  • 5,484
16 votes

10.0.2 mapping Association to Dataset warning

This is a bug in the 10.0.2 version of the type inferencer, which now goes inside pure functions†. It's 'harmless' in that the type inference will just give up and fall back on deduction (which is ...
16 votes
Accepted

Change Values in Dataset under Condition

The problem with the query proposed in the question is that it is attempting to apply Select to each row. As @Kuba points out in a comment, the use of ...
  • 67.5k
16 votes
Accepted

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

Mathematica 10.1 almost supports this operation directly: ...
  • 67.5k
16 votes

How to organically merge nested associations?

Update Created an upsert function to update/insert new keys and values into a nested association structure. It automatically inserts nested associations where they ...
  • 39.8k
16 votes
Accepted

How to "flatten" a nested Association?

Another idea: FixedPoint[Association[Normal[#] /. Rule[n_, m_Association] :> KeyMap[Append[n, #] &, m]] &, KeyMap[{#} &, asso]] <...
  • 19.5k
16 votes
Accepted

Pattern matching to a function evaluation inside an Association

Association is HoldAllComplete. Once it is created, its parts will then normally be held unevaluated. Use ...
16 votes

Substitute for Association inside Compile?

For what it's worth, you can work with a HashTable as long as you're willing to put in a bit of effort ...
  • 45.8k
16 votes
Accepted

Evaluated vs. unevaluated Association

Summary The confusion we observe here is largely due to ambiguous use of the symbol Association as an expression head. On the one hand, ...
  • 67.5k

Only top scored, non community-wiki answers of a minimum length are eligible