Questions tagged [aggregate]

Aggregate refers to the process of summarizing grouped data, commonly used in Statistics.

Aggregate refers to the process of summarizing grouped data, commonly used in Statistics. Typically this involves replacing groups of data with single values (e.g. sum, mean, standard deviation, etc.). In SQL databases and data manipulation libraries such as in , this is accomplished with the use of GROUP BY and aggregate functions.

Documentation:

8256 questions
32
votes
7 answers

Compute mean and standard deviation by group for multiple variables in a data.frame

Edit -- This question was originally titled << Long to wide data reshaping in R >> I'm just learning R and trying to find ways to apply it to help out others in my life. As a test case, I'm working on reshaping some data, and I'm having trouble…
user2348358
  • 321
  • 1
  • 3
  • 3
29
votes
3 answers

Aggregate Root references other aggregate roots

I'm currently working a lot with DDD, and I'm facing a problem when loading/operating on aggregate roots from other aggregate roots. For each aggregate root in my model, I also have a repository. The repository is responsible for handling…
29
votes
4 answers

Saving a select count(*) value to an integer (SQL Server)

I'm having some trouble with this statement, owing no doubt to my ignorance of what is returned from this select statement: declare @myInt as INT set @myInt = (select COUNT(*) from myTable as count) if(@myInt <> 0) begin print 'there's…
larryq
  • 15,713
  • 38
  • 121
  • 190
27
votes
6 answers

SQL Server : SUM() of multiple rows including where clauses

I have a table that looks something like the following : PropertyID Amount Type EndDate -------------------------------------------- 1 100 RENT null 1 50 WATER …
Jimmy
  • 16,123
  • 39
  • 133
  • 213
26
votes
2 answers

Elasticsearch - generic facets structure - calculating aggregations combined with filters

In a new project of ours, we were inspired by this article http://project-a.github.io/on-site-search-design-patterns-for-e-commerce/#generic-faceted-search for doing our “facet” structure. And while I have got it working to the extent the article…
Reonekot
  • 402
  • 4
  • 10
26
votes
5 answers

Explanation of the aggregate scala function

I do not get to understand yet the aggregate function: For example, having: val x = List(1,2,3,4,5,6) val y = x.par.aggregate((0, 0))((x, y) => (x._1 + y, x._2 + 1), (x,y) => (x._1 + y._1, x._2 + y._2)) The result will be: (21,6) Well, I think that…
lantis
  • 349
  • 1
  • 4
  • 10
25
votes
7 answers

Group by multiple columns and sum other multiple columns

I have a data frame with about 200 columns, out of them I want to group the table by first 10 or so which are factors and sum the rest of the columns. I have list of all the column names which I want to group by and the list of all the cols which I…
user1042267
  • 303
  • 1
  • 3
  • 8
25
votes
5 answers

Pandas aggregate with dynamic column names

I have a script that generates a pandas data frame with a varying number of value columns. As an example, this df might be import pandas as pd df = pd.DataFrame({ 'group': ['A', 'A', 'A', 'B', 'B'], 'group_color' : ['green', 'green', 'green',…
MartijnVanAttekum
  • 1,405
  • 12
  • 20
25
votes
1 answer

'Could not interpret input' error with Seaborn when plotting groupbys

Say I have this dataframe d = { 'Path' : ['abc', 'abc', 'ghi','ghi', 'jkl','jkl'], 'Detail' : ['foo', 'bar', 'bar','foo','foo','foo'], 'Program': ['prog1','prog1','prog1','prog2','prog3','prog3'], 'Value' :…
marshallbanana
  • 435
  • 1
  • 4
  • 9
24
votes
1 answer

How to sum array along 3rd dimension

What is the canonical way to sum a 3D array along dimension 3 (thereby yielding a matrix)? I know I can apply(A,c(1,2),sum) but (wrongly or rightly) I got the impression from somewhere that using apply is no better than using for loops. I could…
Museful
  • 6,711
  • 5
  • 42
  • 68
24
votes
2 answers

composed_of in Rails - when to use it?

When should you use ActiveRecord's composed_of class method?
user65663
24
votes
2 answers

Is it possible to use Linq to get a total count of items in a list of lists?

We have a simple structure which is just a list of lists, like so... var fooInfo = new List>(); I'm wondering if there's a simple way we can use linq to return the total of all items from the inner lists. For example, if we had…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
23
votes
8 answers

quick/elegant way to construct mean/variance summary table

I can achieve this task, but I feel like there must be a "best" (slickest, most compact, clearest-code, fastest?) way of doing it and have not figured it out so far ... For a specified set of categorical factors I want to construct a table of means…
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
23
votes
5 answers

Entity Framework with LINQ aggregate to concatenate string?

This is easy for me to perform in TSQL, but I'm just sitting here banging my head against the desk trying to get it to work in EF4! I have a table, lets call it TestData. It has fields, say: DataTypeID, Name, DataValue. DataTypeID, Name,…
Phil Figgins
  • 796
  • 1
  • 8
  • 22
23
votes
2 answers

Get values from first and last row per group

I'm new to Postgres, coming from MySQL and hoping that one of y'all would be able to help me out. I have a table with three columns: name, week, and value. This table has a record of the names, the week at which they recorded the height, and the…
user3915795
  • 233
  • 1
  • 2
  • 6