# Questions tagged [gathering]

Questions on gathering, grouping or clustering data based on certain criteria. This is to be used with primary tags such as list-manipulation, string-manipulation or similar tags, with the primary tag indicating the specific use case.

61 questions
22 views

### Merging values of a list of rules where some keys occur more than once

I have a list of rules resembling rules = {{a -> {1, 2, 3}}, {b -> {2, 3, 4}}, {c -> {3, 4, 5}, c -> {4, 5, 6}}} How can I neatly rearrange this to ...
56 views

### Median of multiple lists of points

I have three lists of points that I want to combine, take the median of and then plot. I'm not entirely certain how to combine and median them. They are data points from three different months, and ...
393 views

### Converting built-in Mathematica symbol to C [closed]

I am trying to convert my Mathematica code to C since it can sometimes takes the Mathematica code quite a while to execute since the arrival times lists are hundreds of thousands of counts long, and ...
112 views

### How do I access individual groups after using GroupBy on a Dataset object?

I want to read in an xlsx (Excel) or TSV (tab-delimited) file, assuming this results in a rectangular table of data. Then I after applying GroupBy (using multiple keys), I should have several ...
51 views

### Groupings of the Elements of a List with at Most $k$ Elements

Given a list with $n$ elements and an integer $k$ I want to get a list with all possible groupings of these n elements in sets with at most k elements. For example, given $n=\{1,2,3,4\}$ and $k=3$ I ...
36 views

### Attempting to fill a table with the number of elements in each bin and make a table with the elements in the bins?

I am having some difficulty trying to fill a table with the number of elements in each bin while also making a table that holds the elements in each bin. Okay, let me go over my thoughts: So I have ...
42 views

### GatherBy first entry of data

Assume I have data(sim) below. How can I extract first point on each horizontal line? ...
131 views

### Creating lists within lists by sorting

I've been working with lists and am stuck on creating lists within a list based on the first element within that list. So for instance, if I have the list: ...
49 views

### Speeding up Gather / DatePlus combination

I am working on a project that involves identifying runs of dates that fall within five business days of each other. Given a list of dates in inDates, the following ...
201 views

### Convert association with list key to nested assocations

I have an association that maps {x, y} pairs to values, for example: ...
254 views

### Group by Lengths of Lists [duplicate]

Let’s say, we have a list of lists: Table[0, {30}, RandomInteger[{1, 5}]] which might look like this ...
31 views

### Merge associations always taking the value that satisfies a given test

I have associations look like this: data = {<|a -> {2, l1}, b -> {3, l1}|>, <|a -> {3, l2}, b -> {2, l2}|>} I want the result: ...
305 views

### Taking the weighted mean of parts of a list using another list

I have three lists: data = {1,0,0,0,1,0,1,0}; time = {1,1,1,1,4,4,4,4}; weight = {0.5,0.5,0.5,0.3,0.5,0.6,0.7,0.8}; data ...
78 views

### On GroupBy's *red* argument in nested groupings

The documentation for GroupBy includes the following cases, among others: ...
145 views

### Replace a set of vectors in a list from another set of vectors

I have lists A = {{0,0.1,50,"A"},{200,0.2,120,"E"},{300,0.32,500,"G"},{400,0.33,800,"GO"}} B={{0,0.1,821,"new1"},{310,0.32,911,"new"}} I need to modify ...
523 views

### Split list based on positions contained in another list

The problem Suppose that after importing several files into my nb (x-y dataset, but this procedure should work also for x-y-z datasets), I end up with a nested list similar to: ...
56 views

### Gather element of a list based on their head

I have list of the form {y[-1], y[0], w'[1], y'[0], w'''[-1], z''[-1]} and I would like to gather the elements together based on their heads to have ...
115 views

### Creating 2 separate table from a table using a condition

I want to make two List/Table(B,C) to separate my values from an existing table(A). To illustrate my question, there is my code: ...
172 views

### Components rules from ArrayComponents

What is the most efficient way to get component rules from ArrayComponents, so additionaly to data = {"a", "b", "a"}; cmp = ArrayComponents[data] ...
100 views

### How do you group cycles?

I want to define a function that takes a list of pairs as input and groups cycles, e.g. {{a1,a2},{b1,b2},{a2,a3},{c1,c2},{a3,a1},{b2,b1}} becomes ...
59 views

### Partition lists into sub-lists based on whether they are consecutive or not [duplicate]

I am new to Mathematica and would appreciate any help. I'd like to partition my data which is comprised of {time x analog input} into sublists of consecutive time. In other words, my data looks like ...
105 views

### Dataset row position changed by GroupBy in 11.0.1

Bug introduced in 11.0.0 and persisting through 11.0.1 or later In 10.4.1 and previous versions then using GroupBy in a Dataset ...
90 views

### Group list by rules in sequence using DateDifference and Total

I have a list and would like to group it into sublists using a couple rules. First rule: the date difference between sequential elements is less than 3. Second Rule: the total of the second ...
72 views

### Table from grouping an association by value

I have an Association with lots of key-value pairs. The values are integer numbers from a finite set. I'd like to group all the keys that have a certain number as value, and make a table with values (...
87 views

### Grouping lists by their first elements and deleting some groups

I have a list ...
156 views

### How to merge some sublists in a very large list ?

I simplified my problem as follows, ...
281 views

### Split list when there is an empty row

I am trying to split a list when there is an empty row. I have tried the following: a = {{1, 1, 1}, {2, 2, 2}, {, ,}, {3, 3, 3}}; b = Split[a, # == Null] but my ...
358 views

### Dataset collapsing/reducing

I have a dataset ds with 3 columns named A, B, C. Columns A and B have repeated values. How can I obtain another dataset that contains a list of the values in C for ...
195 views

### binning list of lists in unequal bin lengths

I'm lookin for binning of ...
177 views

### Group matrix values by column [closed]

Original Question: I have a list {{a, 1}, {b, 3}, {c, 1}, {d, 2}, {e, 3}}. I want to be able to group the the first number in each pair that has the same second ...
191 views

### Group Datasets and take minimum/maximum

Good Morning I have the following dataset: And I try to reach this output: key: only one row per key text: join all texts of the rows with the same key (but no duplicates) min: take the lowest ...
215 views

### Creating Association [duplicate]

I have provided a dataset bellow and I would like to store the data as an Association that I can query. Such that e.g. ...
179 views

### Problem with Custom Sort/Split/Gather

Please help me Sort/Split/Gather/Group(by) a set of symbolic expressions! (extreme TL;DR at bottom) I have a set of symbols (which represent 2-vectors in a plane, ultimately) and I want to sort/...
649 views

### Reshaping associations, generalization of GroupBy

Let's say we have a set a\of associations: ...
117 views

### Role of Accuracy in numerical evaluations, SplitBy vs GatherBy

This is a follow-up question to this question. I generated a list by substituting the results of a solve[] routine and set: ...
659 views

### Partition on sublists beginning with a certain marker elements

Say I have the list {{a}, {0, 2, 5}, {5, 4, 1}, {a}, {1, 1, 0}, {1, 4, 2}, {3, 3, 0}, {a}, {3, 2, 0}, {1, 4, 1}} I would like to make sublists of everything ...
242 views

### Grouping by total length of elements grouped

How might one split a list of irregularly-long sublists into groups, each of which is shorter than a specified length? For example, given the following input: ...
828 views

### How to organically merge nested associations?

Suppose I want to construct an association of associations, such as a list of people with attributes: ...
730 views

### GroupBy twice gives different results

Bug introduced in 7.0 or earlier and persisting through 11.1 It took me quite a lot of time to finally trace down to this strange output. I really don't know why. First, I create a list ...
152 views

### Grouping words by their differences

I'm a new guy here and I face a problem. I should pair the following words according to the rule: pair the words, that differ by max. 2 characters, like: ...
383 views

### Exception with GatherBy: gathering complex conjugates

I want to gather the complex-conjugates that are in a list, but with an exception: only if the imaginary part isn't zero. For example: ...
213 views

### Allocate amount A according to the distribution of amount B

I have a cost that varies by category and date. I also have the counts of each item type within each category and date. I want to distribute the cost to each of the item types. I'm trying to use <...
219 views

### Grouping the list of numbers that have common.

I am working on some simple problem. It is like puzzle.. Let's say I have some list input={{1,1},{1,2},{1,3},{2,3},{3,3},{4,4}} Which means 1 can go and back to ...
257 views

### Join nested lists based on first and last elements within each list

I have a nested list like this: test1 = {{1, 3}, {1, 4}, {1, 7}, {2, 1}, {3, 5}, {4, 1}, {5, 2}, {6, 1}, {7, 6}} I want to join the lists together depending on ...
121 views

### GatherBy output with given Shape

I would like to group items in a binary list according to some property like in the following simple example. ...
407 views

### Handy / flexible directory tree operations

Is there any shorter / more handy / more flexible way to get directory tree as a nested Rules/Associations list? I tried to incorporate ...
192 views

Using the code, where ds is data formatted into a Dataset GroupBy[ds, First] // TableForm I get a table that I wanted, but I was wondering if I could somehow use ...
225 views

### GatherBy based on condition imposed on index variable

Excuse me. This might be user specific question but I need your help. I have an indexed data, where positive integers are used for indexing data. I am trying to group data putting condition on index ...