Thanks to Ric and Brian for their references.

Here is my verb stemplot, which assumes non-negative integer data, begins by trimming x digits from the data, and assumes there will be at most three digits in the stem.

 stemplot =: 4 : 0  NB. usage trim stemplot data
 trimy =: <. y % 10 ^ x  NB. trim x digits
 sslf =. /:~ (<. ,. 10 * ] - <.) trimy % 10 NB. sorted data stem ,. leaf
 stem =. ({. {. sslf) + i. >: ({. {: sslf) - {. {. sslf  NB. plot stem
 plot =. 0 ; 0
 for_i. stem do.
 leaves =. {:"1 (i = {."1 sslf) # sslf
 plot =. plot ,. i;leaves
 end.
 (3&":@>@{. , ' ' , ":@>@{:)"1 }. |: plot
 )

    _1 stemplot 1 4 6 2 2
   1 0
   2 0 0
   3
   4 0
   5
   6 0

--Kip Murray

On 3/12/2013 11:46 PM, Kip Murray wrote:
Here is strength of materials data taken from a textbook.

     data =:       33190 32320 23040 24050
     data =: data, 31860 33020 30930 30170
     data =: data, 32590 32030 32720 31300
     data =: data, 26520 30460 33650 28730
     data =: data, 33280 32700 32340 31920

And here is a "stemplot" of the data

     2 stemplot data
  23 0
  24 0
  25
  26 5
  27
  28 7
  29
  30 1 4 9
  31 3 8 9
  32 0 3 3 5 7 7
  33 0 1 2 6

This is a "histogram" in which the first two data digits are labels and
third digits form the bars of the histogram.  The last line, beginning
33, means there are data values beginning with 330 , 331, 332, and 336.
  The plot was originally called "stem and leaf" -- "stem" is the
two-digit column and "leaves" are the individual third digits.

Your mission, should you decide to accept it, is to write verb stemplot.
  Above, 2 stemplot data means trim two digits from the data (that's
what the 2 is for), then produce the character array shown.  Assume
non-negative integer data.  What does your verb do with

     _1 stemplot 2 1 4 2 6

?

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

Reply via email to