Nub operations in J work on "internal" nub,
ordered complete list of unique first occurences.

But how does one go about getting frequencies of an 
"external" nub, an ordered unique list
containing items in given list?

   ]A=: 100+ 5 2 9 5 4 0 9 0   NB. given list
105 102 109 105 104 100 109 100
   ]B=: 100+ i.10              NB. external nub
100 101 102 103 104 105 106 107 108 109
   
   ~.A                         NB. internal nub
105 102 109 104 100
   /:~~.A                      NB. sorted
100 102 104 105 109

   B +/ . (=/)~ A              NB. Ext. freq. 1
2 0 1 0 1 2 0 0 0 2
   
   #/.~ A                      NB. internal freq.
2 1 2 1 2
   (#/.~ ,: ~.) A
  2   1   2   1   2
105 102 109 104 100

   ((B e. ~.) #^:_1 #/.~) /:~A   NB. Ext. freq. 2
2 0 1 0 1 2 0 0 0 2
   
Any other ways? Also it's good to be scalable to higher ranks.

   ]A1=: 100+ ?.2 8$10
106 105 109 102 104 109 100 107
100 104 106 108 103 108 101 102
   
   B +/ . (=/)~"1 A1
1 0 1 0 1 1 1 1 0 2
1 1 1 1 1 0 1 0 2 0

   ((B e. ~.) #^:_1 #/.~)@/:~"1 A1
1 0 1 0 1 1 1 1 0 2
1 1 1 1 1 0 1 0 2 0


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to