也许'休息'不要跨越

时间:2016-10-11 01:54:46

标签: r

是否有任何机构知道如何解决以下错误消息:某些' x'没有计算;也许'休息'不要跨越' x'

的范围
> mydata = read.csv("Income.csv")
> attach(mydata)
> X = Income[!is.na(Income)]#exclude NA value in mydata
> B = seq(floor(min(X)),ceiling(max(X)),by=10)
> hist(X,break=B)
Error in hist.default(X, breaks = B) : 
  some 'x' not counted; maybe 'breaks' do not span range of 'x'
>str(X)
 num [1:747] 53.92 25.32 0.98 13.12 54.88 ...

我已经将seq()从min(X)设置为max(X)为什么还有错误? 顺便说一下,当我设置为= 0.1时,它可以工作,但这不是我想要的 帮我!!

1 个答案:

答案 0 :(得分:0)

在直方图中指定中断的不同方法。

# Generate some data
# Note: I use "ugly" numbers to demonstrate the use of ceiling/floor
set.seed(100);
X <- runif(10000, min = 18720.8, max = 199420.2);

# This will throw an error:
# Error in hist.default(X, breaks = breaks) :
#  some 'x' not counted; maybe 'breaks' do not span range of 'x'
breaks <- seq(floor(min(X)), ceiling(max(X)), by = 10000);
hist(X, breaks = breaks);

# Either specify the number of breaks directly
hist(X, breaks = 100);

# or specify the number of breaks in your sequence of breaks
breaks <- seq(floor(min(X)), ceiling(max(X)), length.out = 100);
hist(X, breaks = breaks);

# or specify the step width in your sequence of breaks.
# Note: Here you have to make sure that you span the full range of X
breaks <- seq(floor(min(X)), 
              ceiling(max(X)) + ifelse(ceiling(max(X)) %% 10000 != 0, 10000, 0), 
              by = 10000);
hist(X, breaks = breaks);

您可以从上一个示例中看到固定的纸槽宽度是如何导致最后一个不是&#34;完全&#34;的纸槽,因为它&#34;延伸&#34;超过X的最大值。