Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting number of times an atom occurs in a table in J language

Tags:

j

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?

like image 345
ADO Avatar asked Dec 09 '25 19:12

ADO


1 Answers

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

like image 187
bob Avatar answered Dec 13 '25 20:12

bob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!