[R] Obtaining the internal integer codes of a factor XXXX

Rui Barradas ruipbarradas at sapo.pt
Mon Mar 25 17:37:55 CET 2013


Hello,

Though I have the same doubt as Bert, the following seems to make more 
sense.

seq_along(levels(fdata))


Hope this helps,

Rui Barradas

Em 25-03-2013 15:37, Dan Abner escreveu:
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list