1

我是 R 的新手。我需要帮助在 R 中创建一个简单的茎叶图。这是我创建茎叶图的数据。它保存在一个文本文件中。

这就是我希望我的茎看起来像叶子的方式。

Stem Leaf
0    1 1 2 2 3 3 4 4 5 5 5 5 6 6 6 7 8 8 8 8 9 9 9 
1    0 0 0 1 2 2 2 2 2 2 3 3 5 6 6 8 9 9 9
2    0 1 2 3 3 4 5 5 6 6 7 8
3    0 0 0 2 3 4 7 8 
4    3 3 4 4 6 8 
5    1 2 5
6    1 5
7    7

现在我将它加载到“R”中并读取它的数据,但是当我运行查看表格时......这就是它的样子。

在此处输入图像描述

它没有显示它应该如何显示。因此,为了制作茎叶图,编写了以下代码。

data2 <- read.csv("C:/Users/jaina/Desktop/question2.txt", header = T)
stem(data2$Leaf)

上面的代码给了我错误Error in stem(data2$Leaf) : 'x' must be numeric

所以有人可以帮我解决这个问题并显示正确的茎叶图。

谢谢你。

数据:

01,01,02,02,03,03,04,04,05,05,05,05,06,06,06,07,08,08,08,08,09,09,09,10,10,10,11,12,12,12,12,12,12,13,13,15,16,16,18,19,19,19,20,21,22,23,23,24,25,25,26,26,27,28,30,30,30,31,32,33,34,37,38,43,43,44,44,46,48,51,52,55,61,65,67
4

1 回答 1

1
data2 <- data.frame(Leaf=c(01,01,02,02,03,03,04,04,05,05,05,05,06,06,06,07,08,08,08,08,09,
                           09,09,10,10,10,11,12,12,12,12,12,12,13,13,15,16,16,18,19,19,19,
                           20,21,22,23,23,24,25,25,26,26,27,28,30,30,30,31,32,33,34,37,38,
                           43,43,44,44,46,48,51,52,55,61,65,67))
stem(as.numeric(data2$Leaf))

输出 :

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

  0 | 11223344555566678888999
  1 | 0001222222335668999
  2 | 012334556678
  3 | 000123478
  4 | 334468
  5 | 125
  6 | 157

这就是你要找的?

于 2017-01-21T20:04:38.397 回答