如何获得R中5位数字的茎和叶图?

问题描述 投票:0回答:1

我一直在试图解决这个问题,但是没有成功。

我必须在R-中绘制以下茎叶图

22|372
23|512, 688, 941
24|706
25|020, 057, 128, 400, 446, 575, 579
26|183, 894, 982
27|671, 711, 744
28|240, 280, 551, 731, 821, 936
29|141, 405, 567, 596, 771, 923
30|001, 180, 296, 578
31|319, 727
32|151, 677, 779, 922, 996
33|276, 404
34|071, 334
36|043, 298
39|244, 453
42|120, 706

这是我使用的代码-

income<- c(30941,25128,32151,26183,23512,32996,33276,42706,32779,42120,29596,28821,30001,25057,33404,28240,28280,29141,25579,25446,27744,36298,39244,30296,34071,22372,28936,25020,29771,30180,34334,39543,23941,36043,27711,26962,29406,25575,28731,31727,31319,25400,26894,27671,28551,24306,29567,32922,32677,23688,29923,30578)

View(income)
stem(income,scale=2, width=100)

我得到的输出是-

The decimal point is 3 digit(s) to the right of the |

  22 | 4579
  24 | 30114466
  26 | 290777
  28 | 236789146689
  30 | 0236937
  32 | 2789034
  34 | 13
  36 | 03
  38 | 25
  40 | 
  42 | 17
r csv
1个回答
0
投票
d = sort(income)
do.call(rbind, lapply(split(d, trunc(d/1000)), function(x){
    before = trunc(x[1]/1000)
    after = x %% 1000
    paste(before, paste(sprintf("%03d", sort(after)), collapse = " "), sep = " | ")
}))
© www.soinside.com 2019 - 2024. All rights reserved.