Does R automatically create levels for factor variables?
I am trying to create linear models and two of my variables are factors - one being 'gender' (male or female). I didn't originally use the levels() function and left them as factor variables and everything ran fine, and for fitting the linear model, i.e:
fit <- lm(variableA~., data=dataset)
coef(fit)
it gave me an intercept for genderMale.
I then decided to use the levels function, i.e:
levels(dataset$gender)=c("0","1")
and cleared the variables, and ran my code again and it made no difference to my answers (my models, my predictions, the mean squared error ect.)
Does this mean I don't need the levels() function?
I'm not sure if i make much sense, and I'm new to R so would appreciate any help, thank you!