  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Average of subgroup of 2nd column, grouped by 1st column ## Average of subgroup of 2nd column, grouped by 1st column Tag : matlab , By : user143038 Date : December 01 2020, 05:00 PM

To fix this issue I hadn't used accumarray before, so due to the comment by @Dan I decided to give it a try.
At first I tried a naive version and used histc to count occurrences to get the desired mean values... (Note that accumarray will sort the output the same order as unique, so mean will be calculated correctly)
``````%// Naive version
ua = unique(A(:,1)); %// use as histc bins (or sorted "group" values)
result = accumarray(A(:,1), A(:,2)) ./ histc(A(:,1), uA);
``````
``````%// one-liner
result = accumarray(A(:,1), A(:,2), [], @mean);
`````` Boards Message : You Must Login Or Sign Up to Add Your Comments .

## Average of rows where column = A within distinct rows on another column grouped by a third column

Tag : sql , By : Denis Chaykovskiy
Date : March 29 2020, 07:55 AM
this one helps. The answer is: It depends.
In my testing, my solution is the slowest of the bunch, regardless of what test data I use. With real life data, it's about half the speed of the fastest solution.

## Google Sheets: how to find the average of values in one column grouped by another column's values?

Tag : google-sheets , By : Olexiy P.
Date : March 29 2020, 07:55 AM
it fixes the issue Let's say I have a Google Sheet with the following data: , By a Pivot Table
``````Range: Sheet1!A1:B7

Rows:
Group by: Column1

Columns:
Group by: Column2

Calculated Field:
Forumula: =AVERAGE=(Column2)
Summarise by: Custom
``````
``````            1   2   3   4   Grand Total
A           1   2   3   4   2.5
B           1   2           1.5
Grand Total 1   2   3   4   2.166666667
``````

## Average on column grouped by another column

Tag : mysql , By : cheese_doodle
Date : March 29 2020, 07:55 AM
Hope this helps I have a MySQL server with a table myTable which has the following columns: , I finally got the answer. I order to get the daily average I can use:
`````` SELECT DATE(FROM_UNIXTIME(timestamp)) AS Date,
AVG(temperature) AS AvgTemp
FROM   `myTable`
GROUP BY DATE(FROM_UNIXTIME(timestamp))
``````
`````` SELECT DATE(FROM_UNIXTIME(timestamp)) AS Date,
HOUR(FROM_UNIXTIME(timestamp)) AS Hour,
AVG(temperature) as AvgTemp
FROM   `myTable`
GROUP BY DATE(FROM_UNIXTIME(timestamp)),
HOUR(FROM_UNIXTIME(timestamp))
``````

## R: Transfer one column into two column header and average the correct grouped data

Tag : r , By : Oli
Date : March 29 2020, 07:55 AM
``````df\$averages = ave(df[,"X5"], df[c("X1", "X2", "X3", "X4")], FUN = mean)
aggregate(averages~., df[c("averages", "X1", "X2", "X3")], range)
#   X1  X2  X3 averages.1 averages.2
#1 aaa bbb ccc        450        888
#2 qqq rrr ttt        400        456
``````

## Add column with average value grouped by column

Tag : python , By : user186435
Date : March 29 2020, 07:55 AM
hop of those help? You could mask the rate column in the dataframe, GroupBy the TYPE and transform with the mean, which will exlude NaNs. The use fillna to replace the values in the masked dataframe:
``````ma = df.rate.mask(df.rate.eq(0))
df['rate'] = ma.fillna(ma.groupby(df.TYPE).transform('mean').fillna(0))

ID  TYPE  rate
0   1    A   2.0
1   2    B   2.0
2   3    C   1.0
3   4    A   2.0
4   5    C   1.0
5   6    C   3.0
6   7    C   8.0
7   8    C   2.0
8   9    D   0.0
`````` 