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.
jim holtman
2012-Nov-18 22:04 UTC
[R] Question about making histogram and x must be numeric
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.
David L Carlson
2012-Nov-18 22:06 UTC
[R] Question about making histogram and x must be numeric
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.