In J, to count the number of times an element occurs in a list in J is:
count =: 4 : '+/x=y'"0 1.
Alternatively, one can use the "member of interval" E. What is the equivalent expression, in J, for counting the number of times an "atom" occurs in a table?
I am also curious why the rank of "count" is given as 1 0 1, when it is specifically defined as a dyad. Why is the monad rank 1 also included? Can "count", as defined above be used as a monad?
I think what you are looking for is to make the table into a list using (Ravel) monadic ','and then proceed as before. So count becomes:
count=: +/@: (= ,) NB. tacit
count=: 4 : '+/ x = ,y' NB. explicit
Cheers, bob
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With