2016-07-30 98 views
0

我有一个对象temp其数据如下所示:R - 如何生成此数据框的直方图?

month mean(dep_delay) 
    (int)   (dbl) 
1  1  10.233333 
2  2  10.687227 
3  3  13.517602 
4  4  14.554477 
5  5  13.264800 
6  6  20.350293 
7  7  20.754559 
8  8  12.619097 
9  9  6.872436 
10 10  5.880374 
11 11  6.103183 
12 12  17.368189 

我使用dplyr和保存这些数据的对象生成该数据defind如下:

class(temp) 
[1] "grouped_df" "tbl_df"  "tbl"  "data.frame" 

我有点新的R和我想生成'temp'的直方图,以便我可以看到数据的分布。然而,声明:

hist(temp)总是会生成以下错误:

Error in hist.default(temp) : 'x' must be numeric 
+0

@ZheyuanLi - 我已经试过了。我得到一个错误:Error in hist.default(temp [[“mean(dep_delay)”]]):'x'必须是数字 –

+0

你试过'hist(as.data.frame(temp)[,2]) '? – aichao

回答

2

它实际上是我第一次看dplyr。我想一个小例子,它似乎工作:

library(dplyr) 
trees <- dbl_df(trees) 

## A tibble: 31 x 3 
# Girth Height Volume 
# <dbl> <dbl> <dbl> 
#1 8.3  70 10.3 
#2 8.6  65 10.3 
#3 8.8  63 10.2 
#4 10.5  72 16.4 
#5 10.7  81 18.8 

hist(trees[[1]]) 

enter image description here

所以我觉得,如果你只是用hist(temp[[2]])你的罚款。

+1

hist(temp [[2]])起作用。谢谢。 –