r/R_Programming • u/SwamiJesus • Sep 30 '17
R recognizing numbers as a categorical variable instead of numeric-how to fix?
Hi guys. I have a homework assignment for a stats class that has us using the the 'Swiss' data set on R. I need to show the distribution for education and describe it with appropriate statistics, but it seems as if its not an numeric variable in R.
Here is the code I used to try to create a histogram:
hist(swiss$education, xlab= "Portion of Population Educated (Percent)", ylab="Frequency", main="Distribution of Population Educated in Switzerland 1888", right=F, col="blue")
Error in hist.default(swiss$education, xlab = "Portion of Population Educated (Percent)", : 'x' must be numeric
I also tried to take the mean and standard deviation:
mean(swiss$education) sd(swiss$education)
and got >>NA for both.
Is there any way for me to convert this to a numeric variable? To my understanding, these are both percent values showing the percent of males that were in agriculture or educated.
Thanks!
View all comments
Show parent comment
1
u/SwamiJesus Sep 30 '17
I just didn't capitalize the "e" in "Education." I'm normally pretty good about that. Thanks for the response though!