Questions tagged [associations]
Questions on the associative data-structure introduced in Mathematica version 10.
574
questions
3
votes
1
answer
72
views
Updating a data table
1. Example data
I have a data table organized as an Association of Associations:
...
0
votes
2
answers
89
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:
...
5
votes
5
answers
568
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!
...
8
votes
6
answers
427
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,...
5
votes
6
answers
322
views
Restrict sorting to a certain range
Example data (revised to include negative values - see comment of @ydd)
...
2
votes
2
answers
92
views
Move rows and columns of an association matrix
Example data:
...
3
votes
4
answers
208
views
Add missing column keys
Example data:
data = {{"1", 50}, {"1", 60}, {"1", 40}, {"2", 15}, {"3", 18}, {"3", 18}};
The first ...
1
vote
1
answer
105
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, ...
6
votes
3
answers
238
views
How do I reset the inner embedded key?
I have a Association:
...
4
votes
3
answers
146
views
How to use key values as another plotting point
I have this list:
...
0
votes
1
answer
58
views
Apply a function to a rectangular subgrid with missing values
Some example data:
...
2
votes
2
answers
69
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 ...
0
votes
0
answers
52
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:
...
5
votes
2
answers
267
views
Sorting with Missing values
I have the following data:
...
4
votes
2
answers
193
views
How to build a ranking matrix
I have the following Association:
...
8
votes
5
answers
417
views
Apply a function row- and columnwise
I want to a apply a function to the 2nd row and 2nd column of an association:
...
1
vote
0
answers
98
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):
...
3
votes
1
answer
80
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 ...
4
votes
1
answer
90
views
How do I fill in these missing keys with empty strings to get a complete Dataset?
This is my original data:
...
4
votes
4
answers
218
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:
<...
12
votes
1
answer
422
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]= <|...
7
votes
2
answers
218
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 ...
3
votes
1
answer
66
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 ...
4
votes
1
answer
78
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 ...
0
votes
1
answer
45
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 ...
2
votes
0
answers
61
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".
...
2
votes
1
answer
44
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
...
1
vote
1
answer
50
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 ...
2
votes
2
answers
113
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 ...
1
vote
0
answers
64
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/...
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:
...
1
vote
1
answer
141
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?
...
0
votes
0
answers
20
views
`Dynamic`caly change values of an association [duplicate]
Here are two attempts to make a slider that changes an value of an association.
...
0
votes
2
answers
72
views
How to make multiple definitions in an elegant way?
Consider the following code:
...
3
votes
2
answers
125
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:
...
6
votes
3
answers
292
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 ...
1
vote
1
answer
100
views
Where does the result of thing["Properties"] come from?
Question
I'll focus on the example
stream=AudioStream@First@$AudioInputDevices
I can do stream@"Properties" to get a ...
0
votes
3
answers
57
views
Efficient and compact replacement for Association in the following case
Consider the following association:
...
4
votes
1
answer
61
views
KeyReplace with text pattern
KeyReplace is a user added function that can be used to replace keys in associations.
From the documentation:
...
1
vote
1
answer
42
views
Replacement for Association in the following case
Consider the following three integrals:
...
2
votes
0
answers
48
views
Incoherence between `AssociateTo`/`KeyDropFrom` and `DownValues`
My version is 13.2 on Mac. When modifying association I find the following incoherences between AssociateTo/KeyDropFrom and <...
1
vote
2
answers
88
views
Construct association depending on itself
I want to construct an association that some of the Values are constructed from other parts of the Values, for the simplest ...
0
votes
0
answers
60
views
Long associations of short associations or the inverse, which one should I use?
I don't have enough experiences of using Association or Dataset, and when operating with nested associations I meet the ...
1
vote
1
answer
115
views
How to update this Association?
I have the following association, assoc:
...
0
votes
1
answer
52
views
Why association slows down compiled function in the following example?
Consider the following code, which generates some data and performs some selections:
...
2
votes
2
answers
63
views
Pattern matching in Association fails in `Set` assignment
I want to define a symbolic-valued function using Set to memoize the result. However, I get different results when using an ...
1
vote
0
answers
94
views
Convert CSV to JSON
I'd like to convert some csv data to json.
The CSV:
...
1
vote
1
answer
64
views
Permutations of Dataset
I have data with missing values. I need all permutations which follow the two rules: Every year must be represented in each draw; and each draw must contain a minimum of two elements for each year. ...
1
vote
2
answers
54
views
Grouping Associations with varying lengths
I have a large dataset that comes to me in lists of four elements. Each list has a type, an identifying number, a year and a return. Here is a small sample
What I need is a dataset in which the ...
2
votes
1
answer
60
views
How do I compose a list from an Association such that the final product matches a fixed percentage of each of four subsets?
My question is in two parts. The first is about picking discrete elements inside a list of Associations to match a fixed percentage of a final sub-list; the second is about overcoming the rounding ...