Conditional Counting in Mathematica
Posted
by
500
on Stack Overflow
See other posts from Stack Overflow
or by 500
Published on 2011-06-24T19:38:22Z
Indexed on
2011/06/25
8:22 UTC
Read the original article
Hit count: 163
Considering the following list :
dalist = {{1, a, 1}, {2, s, 0}, {1, d, 0}, {2, f, 0}, {1, g, 1}}
I would like to count the number of times a certain value in the first column takes a certain value in column 3.
So in this example my desired output would be:
{{1,1,2}, {1,0,1}, {2,1,0}, {2,0,2}}
Where the latest sublist {2,0,2} being read as: When the value is 2 in the first column, a corresponding value (same row in matrices world) in column 3 of 0 is present twice.
I hope this is not to confusing. I added the second Column to convey the fact that the columns are distant to each other.
If possible, no reordering should happen.
EDIT :
{1,2,3,4,5}
{1,0}
are the exact values taken by the columns I am actually dealing with in my data.
I know I am missing the correct description. Please edit if you can and know it. Thank you
© Stack Overflow or respective owner