[英]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
year
、 month
value
中有三列。
I want to average value
considering month
and year
.我想考虑
month
和year
的value
。 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.