Search Results
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 |
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.
32
votes
Accepted
How to organically merge nested associations?
Initial data:
peopleFacts = <|
alice -> <|age -> 29, shoeSize -> 7|>,
bob -> <|age -> 27, sex -> male, hair -> <|Color -> RGBColor[1, 0, 0]|>
|>
|>;
Here is a version of RecurAssocM …
26
votes
Accepted
Partition on sublists beginning with a certain marker elements
Split[list, (#2 =!= {a}) &]
{
{{a}, {0, 2, 5}, {5, 4, 1}},
{{a}, {1, 1, 0}, {1, 4, 2}, {3, 3, 0}},
{{a}, {3, 2, 0}, {1, 4, 1}}
}
If you add Map@Rest you will get the first form.
Alternative …
9
votes
Creating 2 separate table from a table using a condition
n = 10^4;
data = RandomReal[{0, 1}, {n, 2}];
split = GatherBy[data, #.# >= 1 &];
ListPlot[split, AspectRatio -> Automatic, Epilog -> Circle[]]
8
votes
Gather list elements by labels
I'm always afraid in case of list-manipulation that there was a duplicate in the past. But I do not remember.
You can try this:
Extract[list, Position[labels, #]] & /@ Union@labels
{{{1 ,2}, { …
8
votes
Dataset collapsing/reducing
Failed to find a duplicate:
by = {"A", "B"};
Values @ GroupBy[ds, Query[by], MapAt[First, List /@ by] @* Merge[Identity]]
or:
ds // GroupBy[Query[{"A", "B"}] -> (#C &)] // KeyValueMap[<|#, "Cli …
7
votes
Accepted
Split list when there is an empty row
Read carefully documentation of Split, you need its friend SplitBy:
SplitBy[a, MemberQ[Null]]
{{{1, 1, 1}, {2, 2, 2}}, {{Null, Null, Null}}, {{3, 3, 3}}}
7
votes
Convert association with list key to nested assocations
Merge[
KeyValueMap[ #[[1]] -> <|#[[2]] -> #2|> &, asso]
, Association
]
<|0 -> <|0 -> "a"|>, -1 -> <|-4 -> "b", 1 -> "c", 0 -> "d"|>, 1 -> <|0 -> "e"|>|>
For deeper examples {1,2,3,4,1}-> …
6
votes
Grouping words by their differences
words = {"horse", "horses", "morse", "morses", "norse", "norses",
"fox", "monses", "goose", "tool", "goal", "tools", "gothe"}
I'm not very experienced with Graphs so any advice, how to make it sh …
6
votes
Accepted
Creating Association
GroupBy[dataSet, First -> Last]
Is that ok?
6
votes
Grouping lists by their first elements and deleting some groups
KeyValueMap[
If[Length[#2] == 1, Nothing, Join[##]] &
] @ GroupBy[data, Most -> Last]
{{1, 4, 1, -3, -1}, {1, 5, 2, -4, -1}, {1, 5, 4, -3, -2}, {1, 6,
3, -5, -1}, {1, 7, 4, -6, -1}, {1, 8, …
4
votes
How would you efficiently implement BinListsBy?
This probably won't be the fastest but worth to add:
Last @ Reap[Scan[Sow[#, Floor[#[[ 1]]/10]] &, data],
Range[2, 7]]
{{ {{21, "Alice"}, {27, "Bob"}, {22, "Charles"}}},
{{{34, "D …
4
votes
Taking the weighted mean of parts of a list using another list
Merge[Mean@*Apply[WeightedData]@*Transpose]@ Thread[time -> {data, weight}\[Transpose]]
4
votes
Merge associations always taking the value that satisfies a given test
Merge[data, First @* MaximalBy[First]]
<|a -> {3, l2}, b -> {3, l1}|>
4
votes
Accepted
Formatting plot of symmetric points differently to asymmetric points
list = DeleteDuplicates@RandomInteger[{-10, 10}, {155, 2}];
axis = 1/2;
First let's gather points with the same distance form your axis and the same second coordinate.
Those which have simmetric p …
3
votes
Accepted
Table from grouping an association by value
GroupBy[a, Identity, Keys] // Dataset