I know you can use relevel
to set a value as the reference level of a factor.
I want to do the opposite: given a factor column, how can I retrieve the reference value?
I guess the most trivial way would be to run a regression with lm
and see which value is missing from the estimated coefficients.
Is there a method/function for this?
I feel silly asking this, but searching how to retrieve the reference level of a factor results in tons of questions asking how to relevel a factor (such as this one). I couldn't find anything on how to do the opposite, so I apologize in advance in case this is a duplicate!
Lotus is right.
The reference is the first level of the factor, so you can just use
levels(x)[1]
.