Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 19542

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

3 votes

Can association be used to find the maximum key less than a specific number?

I believe this is of higher order than you are looking for but it works with an Association. Max@Select[Keys[assoc], # <= 10 &] (* 7 *) Keys gets the keys, Select grabs those less than equal to 10, …
Edmund's user avatar
  • 43.2k
2 votes

Attempting to modify parts of a multi-level association in-place

You can create/assign a key/value directly by using the resetting values syntax. m2 = <|"M" -> <|1 -> {1, 2, 3}, 2 -> {2, 3}|>, "F" -> <|1 -> {}, 2 -> {}|>|>; m2["M"]["b"] = 3; m2 (* <|"M" -> <|1 - …
Edmund's user avatar
  • 43.2k
4 votes

Apply function to nested associations

MapAt[MatrixForm, test, {{"correlation"}, {"descendants", "correlation"}}] If "descendants" contains a list of Associations then {"descendants", All, "correlation"} instead. Hope this helps. …
Edmund's user avatar
  • 43.2k
1 vote

Is there a way to order elements in an Association?

You may use Query and Select. Query[Select[Between[{0, 3}]@Length@# &] /* SortBy[Length]]@assoc <|F14->{},F17->{},F3->{},F66->{},F19->{S51},F20->{S51},F32->{S51},F35->{S51},F39->{S51},F41->{S51},F …
Edmund's user avatar
  • 43.2k
8 votes

Why association pattern unmatched when using variable

You may use KeyValuePattern. With assoc = <|id -> 6, dur -> 10, skill -> 1, succ -> {7}, dl -> 250|>; last = 7; then the following return True. MatchQ[assoc, KeyValuePattern[succ -> {___, last, ___}] …
Edmund's user avatar
  • 43.2k
3 votes

Short way to query Dataset by the value of several columns

If you have your $\{column, value\}$ pairs in a list findList = {{"x1", myX}, {"x2", myX}, {"x3", myX}, {"x4", myX}}; then you can build the Select criteria function from it. selectCriteria[find_L …
Edmund's user avatar
  • 43.2k
4 votes

Get association element that has a parameter

You can Select from the Keys of the Association the elements with Head equal to second and then pick out the parameter from second. Select[Head@# === second &]@Keys[assoc] /. second[p_] -> p (* {para …
Edmund's user avatar
  • 43.2k
1 vote

Aliases for keys?

It seems you have already done it with Alternative. c = <|"Major" | "Maj" -> {0, 4, 7}, "Minor" | "Min" -> {0, 3, 7}|>; You would just need KeySelect and MatchQ. KeySelect[MatchQ[#]@"Major" &]@c …
Edmund's user avatar
  • 43.2k
3 votes
Accepted

Applying KeyDrop to a String Pattern

If you have also have strings that are not words you may use DictionaryWordQ. assoc = <|000 -> 2, .60 -> 1, .04348 -> 1, "able" -> 1, "24km" -> 3|>; KeySelect[assoc, Quiet[DictionaryWordQ[#, IgnoreCa …
Edmund's user avatar
  • 43.2k
4 votes

Function like KeyMap that combines values in case of key collisions

You may use Query to improve performance. ClearAll[keyCombine]; keyCombine[fun_, asc_?AssociationQ, comb_ : Identity] := asc // Query[Normal /* GroupBy[fun@*Keys]] // Query[All, (Values@# &) /* …
Edmund's user avatar
  • 43.2k
0 votes

Joining two datasets if second is association of associations

You could alter the GroupBy to return the structure you desire. dReduced = d[ GroupBy["id"] /* Values , Transpose /* Query[{"id" -> First, Sequence @@ Thread[Range[2, 3] -> Total]}] /* …
Edmund's user avatar
  • 43.2k
16 votes

How to organically merge nested associations?

It automatically inserts nested associations where they do not exists and does not need to be assigned back to the original association. It updates existing keys when they are found. …
Edmund's user avatar
  • 43.2k
2 votes

Min and Max of a list of Associations

You may use Query and MinMax. With x as in OP. Query[Transpose /* Map[MinMax]]@x <|"a" -> {4, 21}, "b" -> {3, 11}, "c" -> {1, 21}|> You can produce a more descriptive result with AssociationTh …
Edmund's user avatar
  • 43.2k
4 votes

How can I join some values in rows to be value columns in a dataset/association

dat = Dataset@KeyUnion@associations Now with GroupBy a single hierarchical Dataset can be created. …
Edmund's user avatar
  • 43.2k
7 votes

Merge two database with a common key

You may use JoinAcross with Dataset or Association. I show with Dataset below. To perform with Association remove the Postfix and Dataset from dsCompounds and dsProperties. Also, you may find the Ch …
Edmund's user avatar
  • 43.2k

15 30 50 per page