mode(DATA$COLOR) is "numeric" because R internally stores factors in the form of numeric codes (to save space) plus the associated vector of labels corresponding to the code values. When you print the coefficient, R automatically replaces the corresponding label for each code.
f <- factor(c("orange","banana","apple")) ## [1] orange banana apple ## Levels: apple banana orange str(f) ## Factor w/ 3 levels "apple","banana",..: 3 2 1 c(f) ## strip attributes to get a numeric vector ## [1] 3 2 1 attributes(f) ## $levels ## [1] "apple" "banana" "orange" ## $class ## [1] "factor"
... I need to write R code to return the levels of the COLOR variable ...
levels(DATA$COLOR)
... then determine the current reference level of this variable,
levels(DATA$COLOR)[1]
... and finally set the reference level of this variable to white.
DATA$COLOR <- relevel(DATA$COLOR,"White")
source share