【问题标题】:How to get a stem and leaf plot for 5 digit numbers in R?如何在R中获得5位数字的茎叶图?
【发布时间】:2020-06-16 01:26:33
【问题描述】:

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

我必须在 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 plot


【解决方案1】:
d = sort(income)
n = 3
d2 = sapply(split(d, trunc(d/10^n)), function(x){
    before = trunc(x[1]/10^n)
    fmt = paste0("%0", n, "d")
    after = toString(sprintf(fmt, sort(x %% 10^n)))
    paste(before, after, sep = " | ")
})

for(x in d2){
    cat(x)
    cat("\n")
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多