r - 直方图超出范围
问题描述
我有下面的代码;
断点 <- 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”未计算在内;也许“breaks”不跨越“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
推荐阅读
- r - R将具有特定名称模式的文件移动到不同子目录中的文件夹
- javascript - 在 css 语句中反应原生样式表多个值
- react-native - 无论窗口大小如何,组件都只能通过滚动来访问
- python - IronPython:将 C# 列表转换为 IronPython.Runtime.List
- javascript - Google Places API 的 Fetch 请求出错
- python-3.x - 循环和爬虫项目并将元素保存为 Python 中的 json 格式
- python-3.x - 从导入的模块中终止多进程
- spring - Spring 中的注解
- javascript - ng2-smart-table 不显示
- linux - 从不包含某些字符串的文本文件中删除部分