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 1997

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.

0 votes

Summarize a list of pairs / (Using GatherBy and Tally?)

An approach using Reap and Sow: Using: lst = {{"games", "minecraft"}, {"games", "minecraft"}, {"games", "WoW"}, {"books", "book1"}, {"books", "book1"}, {"books", "book1"}, {"books", "book5"} …
ubpdqn's user avatar
  • 64.9k
4 votes

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

Perhaps (apologies if I have misinterpreted): A /. ({_, #[[2]], __} -> # & /@ B)
ubpdqn's user avatar
  • 64.9k
4 votes

Simple way to group the list-indices of equal elements?

You can also used Reap/Sow, e.g. pi[u_] := Reap[MapIndexed[Sow[#2[[1]], #1] &, u]][[2]] So pi[{f, f, g, g, f}] yields {{1, 2, 5}, {3, 4}}
ubpdqn's user avatar
  • 64.9k
5 votes

Gather list elements by labels

This also works: Reap[MapThread[Sow, {list, labels}]][[2]] or an alternatively ordering by tags: Reap[MapThread[Sow, {list, labels}], Union @ labels][[2, All, 1]]
ubpdqn's user avatar
  • 64.9k
2 votes

Group matrix values by column

I am not sure I understand. Here are some ways to group by last element: list={{1, 1}, {1, 3}, {2, 1}, {2, 2}, {2, 3}} GatherBy[list, Last] GroupBy[list, Last] Last@Reap[Sow[{##}, #2] & @@@ list, _, …
ubpdqn's user avatar
  • 64.9k
2 votes

GatherBy based on condition imposed on index variable

Just for fun: Join @@@ ({{1, 2}, {3, 4, 5}, {6}} /.Last@Reap[Sow[{##}, #1] & @@@ testdat, _, Rule]) yields: {{{1, a11, b11}, {1, a12, b12}, {2, a21, b21}, {2, a22, b22}}, {{3, a31, b31}, {3, a …
ubpdqn's user avatar
  • 64.9k