x must be numeric while trying to create histogram in R

ぐ巨炮叔叔 提交于 2019-12-10 20:35:11

问题


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 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

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)

it gives-

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:


  1. It should be col=file[[2]] or col=file[, 2] --- solution given in comment
  2. data import should be in correct way to avoid numeric issue


来源:https://stackoverflow.com/questions/48144470/x-must-be-numeric-while-trying-to-create-histogram-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!