Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

R-histogram error: 'x' must be numeric

5,943 views
Skip to first unread message

D J

unread,
Feb 10, 2006, 8:52:24 AM2/10/06
to
Hi All,

I have problem to plot histogram.

What I did is:

export a .csv file from PSQL database's table.
so, inside this .csv file it looks like:
31.845
24.598
29.1223
24.715
23.1847
24.2321
25.2995
23.4261
30.7873
......

Then, I use command:
score<- read.csv('file.csv', header = FALSE,sep = ",")
hist(score, main = "score")

it gives error msg:
Error in hist.default("score", main = "score") :
'x' must be numeric

Can any of you know about it explain me why?

Thanks a lot.

Eric B

unread,
Feb 10, 2006, 10:00:36 AM2/10/06
to
You have to pull the variable you want to plot out of the "score"
dataset first. If you put in the command as you did above:

score<- read.csv('file.csv', header = FALSE,sep = ",")

type in score again to display it ... and you'll get this

> score
V1
1 31.8450
2 24.5980
3 29.1223
4 24.7150
5 23.1847
6 24.2321
7 25.2995
8 23.4261
9 30.7873

so when you say plot score, R is trying to plot a variable score not
already defined ... so you just have to define it, something like this:

s <- score[,1];
hist(s,main = "score")

Hope that helps

Eric B

Philipp Pagel

unread,
Feb 10, 2006, 10:02:35 AM2/10/06
to
D J <din...@gmail.com> wrote:

> score<- read.csv('file.csv', header = FALSE,sep = ",")
> hist(score, main = "score")

> it gives error msg:
> Error in hist.default("score", main = "score") :
> 'x' must be numeric

read.csv returns a data frame - i.e. a table. Even if it only has one
column it is still a data frame. What you want is this:

hist(score[,1])

Alternatively, you can use scan() to read the file into a vector.

cu
Philipp

--
Dr. Philipp Pagel Tel. +49-8161-71 2131
Dept. of Genome Oriented Bioinformatics Fax. +49-8161-71 2186
Technical University of Munich
http://mips.gsf.de/staff/pagel

0 new messages