Skip to content
Prev 320226 / 398503 Next

Obtaining the internal integer codes of a factor XXXX

Hi everyone,

I understand the process of obtaining the internal integer codes for
the raw values of a factor (using as.numeric() as below), but what is
the best way to obtain these codes for the levels() of a factor (since
the as.numeric() results don't really make clear which code maps to
which level)?


fdata<-factor(c("b","b","c","a","b","c"),labels=c("I","II","III"))
fdata
levels(fdata)

as.numeric(fdata)


I thought something like this would make sense and work, but it throws an error:

as.numeric(levels(fdata))

Thanks!

Dan