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 81335

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.

1 vote

GatherBy[list, f] except with sublists ordered by f's value

SeedRandom[1] list = RandomSample@Range[10] manyLists = Table[RandomSample@list, 10] $$\left( \begin{array}{cccccccccc} 7 & 2 & 9 & 1 & 8 & 3 & 10 & 4 & 6 & 5 \\ 3 & 6 & 9 & 4 & 2 & 5 & 7 & 8 & 10 …
Syed's user avatar
  • 59.4k
6 votes
Accepted

Strange behavior of Gather with DateObject

Compare the outputs of: Gather[l, #1 === #2 &] Gather[l, #1 == #2 &] The default test is SameQ that translates to #1===#2&and this is what you are seeing. Equal does not mean the same. There is a d …
Syed's user avatar
  • 59.4k
1 vote

Grouping lists by their first elements and deleting some groups

I added an entry to the data and made it visible with a Red x to test my solution. Clear["Global`*"]; list = {{1, 4, 1, -3}, {1, 4, 1, -1}, {1, 4, 1, Style[x, Red]}, {1, 4, 2, -2}, {1, 5, 2, -4}, …
Syed's user avatar
  • 59.4k
5 votes

Merging and keeping only the sublists whose first two elements are equal

Clear["Global`*"]; list = {{-9, 3, 2}, {-9, 3, 8}, {-9, 4, 3}, {-9, 4, 4}, {-7, 2, 2}, {-7, 2, 10}, {-7, 3, 4}, {-5, 1, 16}, {-5, 2, 4}, {-3, 1, 4}, {-3, 1, 6}, {3, 1, -14}, {3, 2, -8}, {3, …
Syed's user avatar
  • 59.4k