Linked Questions

63
votes
8answers
8k views

How to efficiently find positions of duplicates?

Is there an efficient way to find the positions of the duplicates in a list? I would like the positions grouped according to duplicated elements. For instance, given ...
39
votes
8answers
3k views

Can this be written well, without loops?

Inspired by this question I would like to know if the following code can be written without explicit loops (For, While, etc.) in a clean, efficient and non-contrived way. I have been unable to do so. ...
17
votes
9answers
1k views

Splitting a list into increasing sublists

I have a list of numbers (say, for example, {1,2,3,4,3,2,1,2,3,4,3,2}), and I want to split it into sublists so that each sublist is the (smallest) sublist whose ...
10
votes
6answers
652 views

Partition a list by count of a number

I want to take this list when the 2 appear 3 times SeedRandom[1] list = RandomChoice[{.2, .5, .3} -> {1, 2, 3}, 20] ...
10
votes
6answers
772 views

Is there concise code for the list operation I want to perform?

Is there any concise syntax for the following partitioning of a list. Given {1, 2, 3, 4}, I want to get the output as shown below. I have tried various function ...
8
votes
6answers
3k views

Simplifying nested If statements

Consider : list = {100,102,103,99,106,107,104,112} I want to consider, extract only the "big moves" of that time series. In this case the moves bigger then 5 ...
12
votes
6answers
629 views

How do I split a list of numbers to monotonic sequences?

Suppose I have: list = {1, 2, 4, 5, 7, 11, 8, 7, 3, 1, -3, -2, 6, 7, 80} And I want to split it to: ...
21
votes
4answers
665 views

Getting lengths of sublists that sum to more than one

I have a long list of numbers, and I'm interested in finding the length of each sublist that totals to more than 1, so for the list ...
8
votes
5answers
263 views

While partitioning the elements in a list using GatherBy, can I correspondingly partition the elements of an unrelated list?

If we have a list like the following: list1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; And we use GatherBy to subpartition is ...
11
votes
3answers
258 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: ...
3
votes
3answers
146 views

Variable iterator in Do Loop (splitting a list)

I have a list in Mathematica that looks like the following: {{92,3},{23,3},{93,3},{63,2},{66,2},{24,4},{94,4},{27,4},{72,4},....} The point is that the second ...
2
votes
1answer
222 views

Automatic text-wrapping in labels in `TimelinePlot`

Part-related to this question and part-related to this one, I would like to make use of the new features of TimelinePlot in 10.3, but would like to incorporate some ...