[R] Question about making histogram and x must be numeric

jim holtman jholtman at gmail.com
Sun Nov 18 23:04:03 CET 2012


Most likely the value you are using in the 'hist' function is a
factor.  It would help if you included an 'str' of the object you are
using.

On Sun, Nov 18, 2012 at 4:45 PM, 9man <lucas_9man at hotmail.com> wrote:
> Hello all,
>
> I hope someone of you can help me out, I have searched other posts as well
> but I can't find any solution to the problem I'm dealing with.
>
> I want to make a histogram from the data Telephone Lines
>
> MDGdataset <-read.csv("MDG_dataset_2010.csv", header=T)
> MDGdatasetAdapted <- subset(MDGdataset, select = c(Country_Code,
> Country_Name, Year, GNI.per.capita..Atlas.method..current.US..,
> Telephone.lines..per.100.people., Internet.users..per.100.people.))
> MDGdatasetAdapted
> MDGdatasetAdapted <- na.omit(MDGdatasetAdapted)
> names(MDGdatasetAdapted) <- c("Code","Country","Year","GNI","Telephone
> Lines","Internet Users")
>
> Then I do as follows:
>
> hist(MDGdatasetAdapted$Telephone.Lines, ylab="Frequency", xlab="Telephone
> Lines per 100 people", main="Frequency of telephone lines per 100 people",
> nclass=100)
>
> To give an example, the first 2 lines of the MDGdatasetAdapted dataset look
> like this:
>   Country_Code                            Country_Name Year
> GNI.per.capita..Atlas.method..current.US.. Telephone.lines..per.100.people.
> Internet.users..per.100.people.
>
> 1            AFG                             Afghanistan 2010
> 410                              0.1                             3.7
>
> What am I doing wrong for getting the message:
> Error in hist.default(MDGdatasetAdapted$Telephone.Lines, ylab = "Frequency",
> :
>   'x' must be numeric
>
> ??
> Please help me out I would be eternally grateful
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Question-about-making-histogram-and-x-must-be-numeric-tp4649979.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.




More information about the R-help mailing list