Error in hist.default(data) : ‘x‘ must be numeric
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Error in hist.default(data) : ‘x‘ must be numeric相关的知识,希望对你有一定的参考价值。
Error in hist.default(data) : 'x' must be numeric
目录
Error in hist.default(data) : 'x' must be numeric
问题:
# 不是数值所以无法绘制直方图;
#define vector
data <- c('1.2', '1.4', '1.7', '1.9', '2.2', '2.5', '3', '3.4', '3.7', '4.1')
#attempt to create histogram to visualize distribution of values in vector
hist(data)
解决:
#class检查类别
#check class
class(data)
[1] "character"
#转化为数值之后再绘图
#convert vector from character to numeric
data_numeric <- as.numeric(data)
#create histogram
hist(data_numeric)
完整错误:
> #define vector
> data <- c('1.2', '1.4', '1.7', '1.9', '2.2', '2.5', '3', '3.4', '3.7', '4.1')
>
> #attempt to create histogram to visualize distribution of values in vector
> hist(data)
Error in hist.default(data) : 'x'必需为数值
以上是关于Error in hist.default(data) : ‘x‘ must be numeric的主要内容,如果未能解决你的问题,请参考以下文章
lme4 升级产生错误消息 Error in `[[<-.data.frame`(`*tmp*`, i, value = integer(0))
Siebel Error: Unable to create the Business Service '(SBL-DAT-00227)
mybatis 数组array参数报错org.apache.ibatis.exceptions.PersistenceException: ### Error querying dat
r 移动列的功能来自http://stackoverflow.com/questions/18339370/reordering-columns-in-a-large-dataframe