简体   繁体   English

如何使用excel以其他列为参考计算一列的平均值

[英]How to calculate the average of a column using other columns as a reference using excel

I have three columns in excel year , month value .我在 excel yearmonth value中有三列。

I want to average value considering month and year .我想考虑monthyearvalue In R language this function is done by group_by().在 R 语言中,这个 function 是由 group_by() 完成的。 In excel how could this be done?在 excel 这怎么可能呢?

year    month   value
2019    1   12
2019    1   34
2019    2   56
2019    2   15
2020    1   16
2020    3   67
2020    4   89
2018    6   123
2018    6   45
2018    7   98
2019    3   53
2019    1   23
2020    1   12
2020    3   1

If one has Office 365 we can use:如果有 Office 365,我们可以使用:

=LET(
    y,A2:A15,
    m,B2:B15,
    v,C2:C15,
    u,SORT(UNIQUE(CHOOSE({1,2},y,m)),{1,2}),
    CHOOSE({1,1,2},u,AVERAGEIFS(v,y,INDEX(u,0,1),m,INDEX(u,0,2))))

Put this in the first cell and it will spill the results.将它放在第一个单元格中,它会溢出结果。

在此处输入图像描述

Once the HSTACK is release we can replace the CHOOSE with it:一旦 HSTACK 被释放,我们就可以用它替换 CHOOSE:

=LET(
    y,A2:A15,
    m,B2:B15,
    v,C2:C15,
    u,SORT(UNIQUE(HSTACK(y,m)),{1,2}),
    HSTACK(u,AVERAGEIFS(v,y,INDEX(u,0,1),m,INDEX(u,0,2))))

Averageifs would do what you want, but you might want to review using the Filter function to duplicate the Group_By() method for other similar procedures. Averageifs会做你想做的事,但你可能想查看使用过滤器 function来复制 Group_By() 方法以用于其他类似过程。 Once grouped, you can sum/average/sort, etc.分组后,您可以求和/平均/排序等。

Averageifs:平均值:

=AVERAGEIFS(C:C,A:A,2018,B:B,6)

Filter:筛选:

=filter(C:C,(A:A=2018)*(B:B=6))
=Average(filter(C:C,(A:A=2018)*(B:B=6)))

See this spreadsheet for examples of both .有关两者的示例,请参阅此电子表格 I realize you're using Excel, but these formulas should work on both (though they are not the same)我知道您使用的是 Excel,但这些公式应该适用于两者(尽管它们不一样)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用公式中其他列的各个值来计算新列? - How to calculate a new column using individual values of other columns in a formula? 如果一列是 NA,则使用 dplyR 计算其他列的行平均值 - If a column is NA, calculate row mean on other columns using dplyR 根据其他列计算平均值 - Calculate the average based on other columns 如何使用R中的查找方法基于其他列计算新列? - How to calculate a new column based on other columns using a lookup approach in R? 如何计算列的平均值? - How to calculate average for columns? R - 使用时间条件计算平均值以及不同列上的其他条件 - R - Calculate average using time conditions and also other conditions on different column 我如何使用 dplyr 跨所有列计算 function,但所有其他列没有 NA 和没有 0? - How i can calculate a function across all columns with one column but all the other column that have no NA and no 0, using dplyr? 如何使用其他两个变量给出的范围标准来计算列平均值? - How to calculate column average with range criteria given by two other variables? 如何使用R计算单个语句中数据框中一列的配对t检验与所有其他列 - How to calculate a paired t-test for one column in a data frame to all other columns in a single statement using R 如何使用分数数据计算可变列数的平均变化 - How to calculate average change over a variable number of columns using score data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM