我有下面的代码;
断点<-seq(从= 0到= 1500000,由= 10000)
hist(movies $ Votes,breaks = breakPoints,main =“ Votes distribution”,col =“ pink”,xlab =“ Votes”)
我得到了错误:
hist.default(movies $ Votes,breaks = breakPoints,main =“ Votes distribution”,:中的错误: 一些“ x”不计算在内;也许“中断”没有跨越“ x”的范围
答案 0 :(得分:0)
首先,让我们通过使用变量x并为其分配一些值来创建可复制的示例。发生此错误是因为'movies $ Votes'包含0到1500000范围之外的值。看下面的例子。第一个运行正常,第二个运行错误(-1超出了我们的指定范围)。
# Values within range
x <- c(0:1500000)
breakPoints <- seq(from = 0, to = 1500000, by = 10000)
hist(x, breaks = breakPoints)
# Contains value ourside of range
x <- c(-1:1500000)
breakPoints <- seq(from = 0, to = 1500000, by = 10000)
hist(x, breaks = breakPoints) # Gives error
我建议运行下面的代码,以了解数据范围的范围。
range(movies$Votes)
如果您需要对数据施加限制,请查看以下问题:
Bound the values of a vector to a limit in R