[R] possible error in stem() function?

Duncan Murdoch murdoch.duncan at gmail.com
Mon Aug 29 22:09:06 CEST 2016


On 29/08/2016 1:42 PM, Zibeli Aton via R-help wrote:
> Using R-3.3.1 on Linux I seem to sometimes get inaccurate stem-and-leaf plots using stem.  For example:
>
>> x <- c(479,482,487,493,494,494,495,496,497,498,498,499,503,504,507,507,508,
> +                 510,511,512,514,516,520,524,525,525,527,534,536,542,545,546,547,549,
> +                 557,559,561,561,563,563,567,568,569,570,572,578,584)
>> stem(x)
>
>   The decimal point is 1 digit(s) to the right of the |
>
>   46 | 9
>   48 | 27344567889
>   50 | 3477801246
>   52 | 0455746
>   54 | 2567979
>   56 | 1133789028
>   58 | 4
>
> This plot is inaccurate since there are no values 469, 483, 484, etc. in the data.

There's a 479, and a 493, etc.  Since you only have even numbered stems 
you get two decades of leaves on each line.  The ones for the 460's 
would precede the ones for the 470's if there were any; you can see that 
does happen in that the 480's do precede the 490's.

Duncan Murdoch

>
> If I remove one value from the input, then the result appears correct:
>
>> x <- c(479,482,487,493,494,494,495,496,497,498,498,499,503,504,507,507,508,
> +                 510,511,512,514,516,520,524,525,525,527,534,536,542,545,546,547,549,
> +                 557,559,561,561,563,563,567,568,569,570,572,578)
>> stem(x)
>
>   The decimal point is 1 digit(s) to the right of the |
>
>   47 | 9
>   48 | 27
>   49 | 344567889
>   50 | 34778
>   51 | 01246
>   52 | 04557
>   53 | 46
>   54 | 25679
>   55 | 79
>   56 | 1133789
>   57 | 028
>
> Is there a limit to the length of the input argument, a bug in the function, or something I'm missing?
>
> Thanks.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list