英文:
How to create a matrix in Excel?
问题
我有一些数据,看起来有点像这样:
| Value_1 | Value_2 | Value_3 |
|---|---|---|
| TRUE | TRUE | FALSE |
| TRUE | TRUE | FALSE |
| TRUE | FALSE | TRUE |
我想创建一个矩阵,统计在同一行中每个值组合被标记为true的次数。所需的输出应该像这样:
| Value_1 | Value_2 | Value_3 | |
|---|---|---|---|
| Value_1 | 3 | 2 | 1 |
| Value_2 | 2 | 2 | 0 |
| Value_3 | 1 | 0 | 1 |
有人知道如何最好地做到这一点吗?我一直在尝试透视表,但没有成功创建符合要求的一个。
英文:
I have some data that looks a bit like this:
| Value_1 | Value_2 | Value_3 |
|---|---|---|
| TRUE | TRUE | FALSE |
| TRUE | TRUE | FALSE |
| TRUE | FALSE | TRUE |
I want to create a matrix which counts the number of times each combination of two values are flagged as true on the same row. So the required output should look like this:
| Value_1 | Value_2 | Value_3 | |
|---|---|---|---|
| Value_1 | 3 | 2 | 1 |
| Value_2 | 2 | 2 | 0 |
| Value_3 | 1 | 0 | 1 |
Does anyone know how best to do this please? I've been fiddling around with pivot tables but haven't managed to make one that works as required.
答案1
得分: 3
如果您使用动态数组公式,它将自动填充:
这只是矩阵乘法,但首先使用 --(双重否定)将 TRUE 和 FALSE 转换为 1 和 0。以下是计算 3 的示例。
另一个选项是使用 SUM 和 INDEX/MATCH,可以拖拽到横向和纵向。
英文:
If you have Dynamic array formulas, this will spill:
=MMULT(--TRANSPOSE(A2:C4),--A2:C4)
This is just matrix multiplication, but first the -- (double unary) converts the TRUE and FALSE to 1 and 0. Here's an example of the calculation of the 3.
Another option using SUM and INDEX/MATCH that can be dragged across and down.
=SUM(INDEX($A$2:$C$4,,MATCH(F$1,$A$1:$C$1,0))*INDEX($A$2:$C$4,,MATCH($E2,$A$1:$C$1,0)))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。





评论