# How to convert nominal data to ratio/ interval data in R? [closed]

I know the question may seem stupid at first glance, but it's only because it's like R has a mind of its own, and doesn't let me in. :)

I did a questionnaire study, and one of the questions was 'For how many years have you been...?' I got 9 different numbers as answers, including both integers and decimals. I had designed the variable I named 'Years' to be a ratio or interval one. However, as I imported the data to R, it took it as a nominal variable with 9 levels. (By the way, the plan is to build a multiple linear regression model.)

How can I choose the type of variable I want to work with?

• how many years as decimal, are you sure? – Erik Hambardzumyan Jan 5 '17 at 2:01
• Yeah, e.g. 2.5, 0.5 etc. – fannilegoza Jan 5 '17 at 2:02
• to the extent of my understanding you want to make it numerical? – Erik Hambardzumyan Jan 5 '17 at 2:02
• Yes, I want to make R treat it as a numerical variable instead of a nominal one. – fannilegoza Jan 5 '17 at 2:03
• try the given code – Erik Hambardzumyan Jan 5 '17 at 2:09

It is worth trying as.numeric (This a diagnosis_result variable from a Training dataset; the same fashion will apply for your variable and dataset)

Train$diagnosis_result<-as.numeric(Train$diagnosis_result)


(the code above is actually the remedy)

as for special cases when you factorize the variable in the desired way

Train$diagnosis_result<-factor(Train$diagnosis_result, levels = c("B", "M"), labels = c(0,1))

Train$diagnosis_result<-as.numeric(levels(Train$diagnosis_result))[Train$diagnosis_result]  • @fannilegoza check str(Train$your_variable) to see the type, if it is num, then you reached your goal – Erik Hambardzumyan Jan 5 '17 at 2:14
• Already done so :) – fannilegoza Jan 5 '17 at 2:15
• Okay. I'm new here. Then not-thanks for the advice. ;) – fannilegoza Jan 5 '17 at 2:20