如何从txt文件中创建R中的茎叶图?

时间:2017-01-21 19:42:30

标签: r plot stem

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

这就是我如何想要让我的东西像LIR-LEAF一样。

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"并读取它的数据,但当我运行查看表...这就是它的样子。

enter image description here

它没有显示它如何显示。所以要使茎叶图写下面的代码。

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

1 个答案:

答案 0 :(得分: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

这是你在找什么?