尝试在R中创建直方图时,x必须为数字 [英] x must be numeric while trying to create histogram in R

查看:559
本文介绍了尝试在R中创建直方图时,x必须为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R中的新手.我需要生成一些图形.我导入了一个excel文件,需要在一列上创建直方图.我的导入代码是-

I am a newbie in R. I need to generate some graphs. I imported an excel file and need to create a histogram on one column. My importing code is-

file=read.xlsx('femalecommentcount.xlsx',1,header=FALSE)
col=file[2]

col看起来像这样(一部分)-

col looks like this (part) -

36961     1
36962     1
36963     7
36964     1
36965     2
36966     1
36967     1
36968     4
36969     1
36970     6
36971     3
36972     1
36973     6
36974     6
36975     2
36976     2
36977     8
36978     2
36979     1
36980     1
36981     1

第一列是行号.我不确定如何删除它.第二列是我想要直方图的数据. hist()函数需要一个向量,我不确定如何精确转换.

the first column is the row number. I'm not sure how to remove this. The second column is my data that I want a histogram on. hist() function requires a vector, I'm not sure how exactly to convert.

如果我只是简单地打电话-

If I just simple call -

hist(col)

它给出了-

Error in hist.default(col) : 'x' must be numeric

我从互联网上随机尝试了一些命令,但是没有用.

I have tried few commands randomly from the internet, but they didn't work.

我的最终目标是仅在该列上生成一个良好的直方图(可能还有其他图表),以很好地了解我的数据传播.

My eventual goal is to just generate a good histogram (and maybe other charts) on that column, to get a good understadning of the spread of my data.

推荐答案

  1. 应该是col = file [[2]]或col = file [,2] ---注释中给出的解决方案
  2. 数据导入应采用正确的方式以避免数值问题

这篇关于尝试在R中创建直方图时,x必须为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆