Skip to main content

Questions tagged [associations]

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

Filter by
Sorted by
Tagged with
4 votes
2 answers
195 views

Reverse association and map through its values/keys

I suspect this could be done in a shorter and more readable code: Challenge: do it without Normal and Association. ...
azerbajdzan's user avatar
  • 18.9k
9 votes
5 answers
370 views

Reconstruct list from its PositionIndex

Is there a more elegant or shorter way of reconstructing a list from its PositionIndex? The following I regard quite cumbersome: ...
azerbajdzan's user avatar
  • 18.9k
5 votes
2 answers
142 views

Nested associations - flatten and unflatten

Assume I have ass = <|"A" -> 1, "B" -> <|"B1" -> 2, "B2" -> 3|>|> I can flatten it to ...
Stefan Gillessen's user avatar
6 votes
6 answers
425 views

Avoiding (numbering) duplicate keys

...
eldo's user avatar
  • 74.7k
3 votes
2 answers
84 views

Multiple append over a Dataset

I have the following association : ...
Jocelyn Minini's user avatar
6 votes
3 answers
304 views

Elegant way to select association elements whose values are not Null or empty list

I'm relatively unfamiliar with associations. I wish to select association elements (i.e., keys and values) whose values are not Null or ...
Andrew's user avatar
  • 10.6k
6 votes
3 answers
130 views

How to add a column to a dataset made up of an association of associations?

A dataset can be created in at least two ways: first, from a list of associations, second, from an association of associations (I know that it is also possible to create it as a list of list and an ...
Emerson Villafuerte's user avatar
4 votes
3 answers
152 views

Why does ListPlot not work out of the box with a list of associations and how to get it to work?

Let us assume I have several sets of data points with labels, e.g.: ...
Editortoise-Composerpent's user avatar
1 vote
0 answers
57 views

Selecting from a list of associations

From a list of Associations ...
eldo's user avatar
  • 74.7k
2 votes
1 answer
108 views

How to force evaluation of RuleDelayed?

(I'm not sure if the title of this question is appropriate, sorry!) After defining selfApply function that resolves the mutual references contained in Association, I wrote the following code: ...
user14061's user avatar
5 votes
5 answers
322 views

Make association with deepest rules from nested association

I want to extract only the deepest level of association in a nested associations. An example of input data is ...
user14061's user avatar
3 votes
0 answers
81 views

Elegant operations on associations and datasets

As a useful extension of this question: Elegant operations on matrix rows and columns I would like to ask: What are for you elegant, short, useful or frequently used functions to use with ...
eldo's user avatar
  • 74.7k
4 votes
2 answers
196 views

How to do AssociationThread recursively?

Consider the following sequence of deepening lists: ...
user13892's user avatar
  • 9,443
3 votes
4 answers
451 views

Find the shortest possible unique keys

1. Problem statement Given a certain rectangular matrix I want to scan its rows from left right to find equally sized sequences. These sequences should be as short as possible and unique, so that they ...
eldo's user avatar
  • 74.7k
4 votes
1 answer
86 views

Updating a data table

1. Example data I have a data table organized as an Association of Associations: ...
eldo's user avatar
  • 74.7k
0 votes
2 answers
93 views

Clip, Select, FirstPosition not working for extracting values from an association based on a range from another list

I have this dataset of associations: ...
atomic-muclei's user avatar
5 votes
5 answers
598 views

Analyzing football games (pairing matrix)

I want to cross-tabulate football games over several years. Setting up example pairings: Please note that there can be up to 20 clubs and a couple of thousand matches! ...
eldo's user avatar
  • 74.7k
8 votes
6 answers
444 views

Accumulate up and down

I want to accumulate positive and negative values separately. dt = RandomSample[Range[-10, 10]] {3, -5, 2, -9, 1, -1, 0, 8, 10, 4, -7, 7, -8, -3, 6, -4, -2, 5, -10,...
eldo's user avatar
  • 74.7k
5 votes
6 answers
333 views

Restrict sorting to a certain range

Example data (revised to include negative values - see comment of @ydd) ...
eldo's user avatar
  • 74.7k
2 votes
2 answers
109 views

Move rows and columns of an association matrix

Example data: ...
eldo's user avatar
  • 74.7k
3 votes
4 answers
217 views

Add missing column keys

Example data: data = {{"1", 50}, {"1", 60}, {"1", 40}, {"2", 15}, {"3", 18}, {"3", 18}}; The first ...
eldo's user avatar
  • 74.7k
1 vote
1 answer
121 views

Speed Up Creating a List of Associations

Background I frequently import data from CSV files. This data often has headers, is a mix of numbers and text, and is a simple 2D 'shape'. I need to clean the data (eg removing rows, trimming strings, ...
IntroductionToProbability's user avatar
6 votes
3 answers
242 views

How do I reset the inner embedded key?

I have a Association: ...
yode's user avatar
  • 26.8k
4 votes
3 answers
158 views

How to use key values as another plotting point

I have this list: ...
atomic-muclei's user avatar
0 votes
1 answer
60 views

Apply a function to a rectangular subgrid with missing values

Some example data: ...
eldo's user avatar
  • 74.7k
2 votes
2 answers
80 views

Grouping and rejoining to original lists of associations

I am quite new to associations, and I have been stumbling multiple times over the same issue: I want to make calculations on a GroupedBy list of associations and ...
jabberwocky's user avatar
0 votes
0 answers
64 views

Plotting a list of associations on same plot and creating legends for each one

I have a list of associations that look like this and it goes on for more ts: ...
atomic-muclei's user avatar
6 votes
2 answers
272 views

Sorting with Missing values

I have the following data: ...
eldo's user avatar
  • 74.7k
4 votes
2 answers
210 views

How to build a ranking matrix

I have the following Association: ...
eldo's user avatar
  • 74.7k
8 votes
5 answers
431 views

Apply a function row- and columnwise

I want to a apply a function to the 2nd row and 2nd column of an association: ...
eldo's user avatar
  • 74.7k
1 vote
0 answers
99 views

How to make the association's keys viewable by opener in input cell in editable form?

I have an association as follows (the actual association has hundreds of keys): ...
user13892's user avatar
  • 9,443
4 votes
1 answer
88 views

Two-dimensional associative array such as p["A"][[n]]

I am trying to use Associations in order to clean up / factorize my code but am still confused about how these work. In the code below, I have an object p which is 2-dimensional (or rather I am hoping ...
tyogi's user avatar
  • 289
5 votes
1 answer
106 views

How do I fill in these missing keys with empty strings to get a complete Dataset?

This is my original data: ...
yode's user avatar
  • 26.8k
6 votes
6 answers
246 views

How to regroup elements of a cluster?

Given a clustering of unique elements, clustering = {{10, 40, 30}, {200, 500}, {6}, {7}, {8}}; How do I group a given subset of them into the same cluster? eg: <...
IntroductionToProbability's user avatar
12 votes
1 answer
435 views

Strange behaviour of an association

This an almost MWE of a problem I encountered when working with associations. asc1 = <| |>; asc1[1] = Range[0, 9]; asc1[2] = Range[0, 9]; asc1 Out[150]= <|...
Fred Simons's user avatar
  • 10.2k
7 votes
2 answers
237 views

How to GroupBy or Gather on a nested association

I've been trying to figure out how to gather or group on a list of a nested associated--and flailing. Here is a reduced example. I'm interested in performance as the is for a larger example and the ...
Craig Carter's user avatar
  • 4,510
3 votes
1 answer
69 views

How to shorten the output of an Association

I'm writing a function that steps through a parameter and returns the outputs of NDSolve to make crude bifurcation diagrams. It seems like an ...
Chris K's user avatar
  • 20.3k
4 votes
1 answer
126 views

On displaying association, including all items in a nice way?

Currently I use Dataset to display an association in a nice to see way on the screen. However, only top level items are shown this way. And have to click on each ...
Nasser's user avatar
  • 145k
0 votes
1 answer
70 views

Having issues creating rules from a CSV import

I'm importing a CSV file with two columns. I've done this with other files, but this one is causing issues when trying to create rules to associate IDs with the titles. Here's a sample of the ...
Sam B's user avatar
  • 159
2 votes
0 answers
65 views

Is there a way to refer to the value of another key in the same association?

I have an association like below and want to know how to properly phrase the value for winner. in this example, the answer should be "a". ...
Indiana's user avatar
  • 331
2 votes
1 answer
49 views

How to equate the list elements to values list in a compact way?

Consider some list of keys keys={"1","2","3","4"} and the list of values ...
John Taylor's user avatar
  • 5,827
1 vote
1 answer
55 views

How to extract keys from the following definitions (not the standard association)?

Consider some example definitions: abba["1"] = 1; abba["2"] = 2; For some reason, I do not want to introduce the other form of representation ...
John Taylor's user avatar
  • 5,827
3 votes
3 answers
141 views

Is there a way to divide associations by key?

I have the following two associations <|A->2.02015,B->1.98025|> <|B->0.538000,A->0.462000|> I would like to produce a third association ...
Indiana's user avatar
  • 331
1 vote
0 answers
69 views

How to Name a Path in TemporalData?

Preamble: I am working with stock prices and need to perform calculations on them. And then extract the information for further calculations. TimeSeries/...
IntroductionToProbability's user avatar
0 votes
2 answers
33 views

Error when passing variable into Block and NumberForm

I made this pseudo-code that highlights what is happening. Assume the following dictionary: ...
Giovanni Baez's user avatar
1 vote
1 answer
219 views

How can I invert the association? [duplicate]

Consider an association assoc := Association[{"a" -> 1, "b" -> 2} ] How can I invert it, i.e., to obtain the following? ...
John Taylor's user avatar
  • 5,827
0 votes
0 answers
21 views

`Dynamic`caly change values of an association [duplicate]

Here are two attempts to make a slider that changes an value of an association. ...
Jineon Baek's user avatar
0 votes
2 answers
88 views

How to make multiple definitions in an elegant way?

Consider the following code: ...
John Taylor's user avatar
  • 5,827
3 votes
2 answers
140 views

How to create a GroupBy function that is better aligned with relational algebra?

I want a GroupBy function that behaves more in alignment with relational algebra principles. I can get what I want if I do it in 2 steps: Preparation: ...
Luxspes's user avatar
  • 930
7 votes
4 answers
345 views

Apply pattern using a Slot (#) to each list element using a second slot

I am trying to find a neat way of applying an operation to each list element, but do not know how to properly use multiple slots or whether it is actually possible to solve this with multiple slots. I ...
michelangelov's user avatar

1
2 3 4 5
12