2016-07-30 44 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]])起作用。謝謝。 –