Hello,
I want to do a linear regression model, and I've some categorical values (string values).
I have two questions:
-
When I want to convert from string to numeric, it's not clear to me: Does the values I assign for a string value matter? Or, if I have for example, c('rich', 'average', 'poor'), it doesnt matter if I assign 1 to rich, 2 to poor and 3 to average or whatever the order?
-
What is the easiest and fatest way to convert a column of a dataframe from strings values to numerical values? For the moment, this is how I do it:
# Creation of a temporary vector with all the conversions I give
functional.list <- c('None' = 0, 'Sal' = 1, 'Sev' = 2, 'Maj2' = 3, 'Maj1' = 4,
'Mod' = 5, 'Min2' = 6, 'Min1' = 7, 'Typ'= 8)
# Conversion => I assign the values in df.numeric in a new column called Functional
df.numeric['Functional'] <- as.numeric(functional.list[df.fulldata$Functional])
Thanks for your help!