Questions tagged [grouping]

The process of grouping entities into collections of associated elements.

Grouping is a form of hierarchical knowledge representation, similar to mind mapping, concept mapping and argument mapping, all of which need to observe at least some of the principles of grouping.

SQL Server - Indicates whether a specified column expression in a GROUP BY list is aggregated or not. Read more about this

Wiki Links

7381 questions
397
votes
33 answers

How can I group an array of objects by key?

Does anyone know of a way (lodash if possible too) to group an array of objects by an object key then create a new array of objects based on the grouping? For example, I have an array of car objects: const cars = [ { 'make': 'audi', …
Trung Tran
  • 13,141
  • 42
  • 113
  • 200
254
votes
5 answers

SVG Positioning

I'm having a play with SVG and am having a few problems with positioning. I have a series of shapes which are contained in the g group tag. I was hoping to use it like a container, so I could set its x position and then all the elements in that…
ChrisInCambo
  • 8,455
  • 15
  • 50
  • 63
159
votes
13 answers

Group a list of objects by an attribute

I need to group a list of objects (Student) using an attribute (Location) of the particular object. The code is like below: public class Grouping { public static void main(String[] args) { List studlist = new…
Dilukshan Mahendra
  • 3,230
  • 7
  • 41
  • 62
147
votes
11 answers

using lodash .groupBy. how to add your own keys for grouped output?

I have this sample data returned from an API. I'm using Lodash's _.groupBy to convert the data into an object I can use better. The raw data returned is this: [ { "name": "jim", "color": "blue", "age": "22" }, { …
user1767105
  • 1,919
  • 3
  • 15
  • 10
140
votes
8 answers

How can I group data with an Angular filter?

I have a list of players which belong to a group each. How can I use a filter to list the users per group? [{name: 'Gene', team: 'team alpha'}, {name: 'George', team: 'team beta'}, {name: 'Steve', team: 'team gamma'}, {name: 'Paula', team: 'team…
Benny Bottema
  • 11,111
  • 10
  • 71
  • 96
132
votes
20 answers

Identify groups of consecutive numbers in a list

I'd like to identify groups of consecutive numbers in a list, so that: myfunc([2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 20]) Returns: [(2,5), (12,17), 20] And was wondering what the best way to do this was (particularly if there's something inbuilt…
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
106
votes
21 answers

How to group subarrays by a column value?

I have the following array Array ( [0] => Array ( [id] => 96 [shipping_no] => 212755-1 [part_no] => reterty [description] => tyrfyt [packaging_type] => PC ) [1] =>…
Red
  • 6,230
  • 12
  • 65
  • 112
101
votes
16 answers

How to select the first row for each group in MySQL?

In C# it would be like this: table .GroupBy(row => row.SomeColumn) .Select(group => group .OrderBy(row => row.AnotherColumn) .First() ) Linq-To-Sql translates it to the following T-SQL code: SELECT [t3].[AnotherColumn],…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
98
votes
6 answers

Spark difference between reduceByKey vs. groupByKey vs. aggregateByKey vs. combineByKey

Can anyone explain the difference between reducebykey, groupbykey, aggregatebykey and combinebykey? I have read the documents regarding this, but couldn't understand the exact differences. An explanation with examples would be great.
Arun S
  • 1,363
  • 3
  • 13
  • 17
91
votes
16 answers

Add separator to string at every N characters?

I have a string which contains binary digits. How to separate string after each 8 digit? Suppose the string is: string x = "111111110000000011111111000000001111111100000000"; I want to add a separator like ,(comma) after each 8 character. output…
Abdur Rahim
  • 3,975
  • 14
  • 44
  • 83
87
votes
9 answers

Group list by values

Let's say I have a list like this: mylist = [["A",0], ["B",1], ["C",0], ["D",2], ["E",2]] How can I most elegantly group this to get this list output in Python: [["A", "C"], ["B"], ["D", "E"]] So the values are grouped by the secound value but the…
Veles
  • 1,512
  • 4
  • 14
  • 28
69
votes
7 answers

Group rows in an associative array of associative arrays by column value and preserve the original first level keys

I have an array of subarrays in the following format: [ 'a' => ['id' => 20, 'name' => 'chimpanzee'], 'b' => ['id' => 40, 'name' => 'meeting'], 'c' => ['id' => 20, 'name' => 'dynasty'], 'd' => ['id' => 50, 'name' => 'chocolate'], …
Anson Kao
  • 5,256
  • 4
  • 28
  • 37
61
votes
7 answers

Is there a "Group Box" equivalent in Java Swing?

Trying to build a GUI application in Java/Swing. I'm mainly used to "painting" GUIs on the Windows side with tools like VB (or to be more precise, Gupta SQLWindows... wonder how many people know what that is ;-)). I can't find an equivalent of a…
Thorsten
  • 12,921
  • 17
  • 60
  • 79
59
votes
5 answers

How to group elements in python by n elements

Given a list [1,2,3,4,5,6,7,8,9,10,11,12] and a specified chunk size (say 3), how can I get a list of chunks [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]?
TheOne
  • 10,819
  • 20
  • 81
  • 119
57
votes
16 answers

javascript | Object grouping

I have an object. It looks like below: [ { "name":"Display", "group":"Technical detals", "id":"60", "value":"4" }, { "name":"Manufacturer", "group":"Manufacturer", "id":"58", "value":"Apple" }, { …
XTRUST.ORG
  • 3,280
  • 4
  • 34
  • 60
1
2 3
99 100