HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

Changing a character into a number #92

Open EmiliaSicari opened 8 years ago

EmiliaSicari commented 8 years ago

Rafael and I were wondering if there's a way to convert a character into a number on Rstudio. For example check the data set of "women" included in R: the variables "height" and "weight" are considered characters even though they are numbers; therefore, it's not possible to calculate some statistics!!

Thanks a lot! :)

christophergandrud commented 8 years ago

If you have a data frame called data and a variable called height then use as.numeric like this:

data$height <- as.numeric(data$height)