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

David L Carlson dcarlson at tamu.edu
Sun Nov 18 23:06:51 CET 2012


You tried setting shorter variable names, but the two lines of your data set
that you gave us still have the original names, eg.
Telephone.lines..per.100.people.

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of 9man
> Sent: Sunday, November 18, 2012 3:45 PM
> To: r-help at r-project.org
> Subject: [R] Question about making histogram and x must be numeric
> 
> 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.




More information about the R-help mailing list