Given the various definition here, I think I'd implement stem and leaf
plots like this:

stem=: }:@":&.>
leaf=: {:@":&.>

stemleaf=:2 :0
  y=./:~ y
  s=. u y
  (,.>~.s) ; >s <@;/. v y
)


Example (using >,./ to avoiding boxes because email clients mishandle boxes):

   ,./ >stem stemleaf leaf i:12
_1        210
_         987654321
          0123456789
1         012

The point is that you can define stem and leaf arbitrarily, the
definitions I used here is just an example.  I assumed they produce
boxed strings but leaf should probably be constrained to produce a
single character, and both should probably be constrained to rank 0.

I haven't seen enough examples of the %5 and %2 cases to know how to
define stem consistently there, but hypothetically it should not be
complicated.

However, for the %10 case:

   stem=: [: ((i.~ '';(,'_');]) { (,'0');'_0';]) }:@":&.>

   ,./ >stem stemleaf leaf i:12
_1        210
_0        987654321
0         0123456789
1         012

You might also want to postprocess the result (stem stemleaf leaf) to
right justify the stems.

FYI,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to