我有下面的代码;
breakPoints < - seq(from = 0,to = 1500000,by = 10000)
hist(movies $ Votes,breaks = breakPoints,main =“Votes distribution”,col =“pink”,xlab =“Votes”)
我收到错误:
hist.default中的错误(电影$ Votes,break = breakPoints,main =“投票发行”,:某些'x'未计算;可能'中断'不跨越'x'的范围
首先,让我们通过使用变量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