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 ...
WReach's user avatar
  • 68k
32 votes
Accepted

How to organically merge nested associations?

Initial data: ...
Kuba's user avatar
  • 135k
28 votes
Accepted

Assign names to Dataset columns

data = N @ Normalize[#, Total] & @ Counts @ Characters @ ExampleData[ {"Text", "DeclarationOfIndependence"} ]; Dataset @ data ...
Kuba's user avatar
  • 135k
27 votes

Difference between HashTable datastructure and Association datastructure

Summary Important differences between Association and CreateDataStructure["HashTable"] include: associations are ...
WReach's user avatar
  • 68k
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 ...
Leonid Shifrin's user avatar
22 votes

Reverse Lookup: getting keys from values

PositionIndex[assoc][<value>] For example: ...
user1066's user avatar
  • 12.5k
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) ...
WReach's user avatar
  • 68k
21 votes

Assign names to Dataset columns

Actully we have a easiest way,suppose you have dataset like ...
yode's user avatar
  • 25.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: ...
Carl Woll's user avatar
  • 127k
19 votes

How to switch from List of rules to Association?

The undocumented function ToAssociations in the GeneralUtilities package does this ...
Daniel W's user avatar
  • 3,376
19 votes

Reverse Lookup: getting keys from values

One way would be to "invert" the association and then look up values in the result: ...
WReach's user avatar
  • 68k
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 ...
Albert Retey's user avatar
  • 23.5k
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 ...
WReach's user avatar
  • 68k
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 ...
Mr.Wizard's user avatar
  • 267k
17 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 ...
Leonid Shifrin's user avatar
16 votes
Accepted

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

Mathematica 10.1 almost supports this operation directly: ...
WReach's user avatar
  • 68k
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 ...
Edmund's user avatar
  • 40.9k
16 votes
Accepted

How to "flatten" a nested Association?

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

Convert List of Associations into Association of Lists

You can use the undocumented AllowedHeads option of Transpose to do this: ...
Carl Woll's user avatar
  • 127k
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 ...
b3m2a1's user avatar
  • 46.3k
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, ...
WReach's user avatar
  • 68k
15 votes
Accepted

Reshaping associations, generalization of GroupBy

One approach is to employ a helper function that unwraps singleton lists: {delist[v_]} ^:= v With this, the GroupBy ...
WReach's user avatar
  • 68k
15 votes
Accepted

Reversing a GroupBy operation

This looks a little simpler: ...
Leonid Shifrin's user avatar
15 votes
Accepted

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

This would seem to really be a question on runtime complexity of Merge, or more specifically in this case Merge[Total]. It seems ...
kirma's user avatar
  • 18.4k
14 votes

Extract all Values from nested Association

Given asso = <|a -> tr, b -> <|c -> <|d -> 12, e -> del|>|>, f -> g|> then directly ...
SquareOne's user avatar
  • 7,455
14 votes
Accepted

Transpose fail in 11.1 Dataset

As observed in the question, the problem lies with the type information of the dataset. Specifically, the type information for the innermost association is missing (i.e. "any type"). This causes the ...
WReach's user avatar
  • 68k
14 votes

Move the outer key inward in an association

Here's an approach using @@@ (Apply at level {1}): ...
Lukas Lang's user avatar
  • 32.1k
13 votes
Accepted

How to switch from List of rules to Association?

Not pretty but works: lst //. x : {__Rule} :> Association[x]
Kuba's user avatar
  • 135k
13 votes
Accepted

Find and return the key with lowest value in association list

Use: Keys @ MinimalBy[Value]@ A {1, "2", 10, 12, 16} About your approach, you can add ...
Kuba's user avatar
  • 135k
13 votes
Accepted

How to mimic thing["property"] syntax?

How can I recreate this sort of functionality with my own objects and functions? Are there any methodologies for writing down-values of symbols like this? If you want to know how to get a similar ...
rhennigan's user avatar
  • 1,783

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