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.
3
votes
Accepted
How to merge or group an association by another association or rule?
Disclaimer: elegancy is subjective and efficiency was not tested.
Merge[Total] @* KeyValueMap[mealType[#] -> #2 &] /@ <|caloriesOfFoodEaten|>
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}-> …
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
Taking the weighted mean of parts of a list using another list
Merge[Mean@*Apply[WeightedData]@*Transpose]@ Thread[time -> {data, weight}\[Transpose]]
3
votes
Replace a set of vectors in a list from another set of vectors
What about:
GatherBy[ Join[A, B], #[[2]] & ][[ All , -1]]
{{0, 0.1, 821, "new1"}, {200, 0.2, 120, "E"}, {310, 0.32, 911,
"new"}, {400, 0.33, 800, "GO"}}
If order does not matter:
DeleteD …
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[]]
3
votes
Accepted
Table from grouping an association by value
GroupBy[a, Identity, Keys] // Dataset
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, …
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}}}
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 …
6
votes
Accepted
Creating Association
GroupBy[dataSet, First -> Last]
Is that ok?
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 …
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 …
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 …
3
votes
GatherBy based on condition imposed on index variable
group = (Switch[#,
1 | 2 | 3, 1,
_, 2
] &);
GatherBy[testdat, group[ #[[1]] ] & ]
{
{{1, a11, b11}, {1, a12, b12}, {2, a21, b21}, {3, a31, b31 …