# R-alpha: factors ...

**Ross Ihaka
**
ihaka@stat.auckland.ac.nz

*Thu, 22 May 1997 08:26:43 +1200 (NZST)*

Kurt Hornik writes:
>* Perhaps someone can enlighten me here:
*
>* R> x <- factor(LETTERS[1:3])
*>* R> x
*>* [1] A B C
*>* R> mode(x)
*>* [1] "factor"
*>* R> class(x)
*>* [1] "factor"
*>* R> mode(unclass(x))
*>* [1] "factor"
*
>* S-PLUS has
*
>* > x <- factor(LETTERS[1:3])
*>* > mode(x)
*>* [1] "numeric"
*>* > class(x)
*>* [1] "factor"
*>* > mode(unclass(x))
*>* [1] "numeric"
*
>* ???
*
Originally, factors in R were implemented as a special type. This was
partly because we didn't have objects at the start, and partly because
S factors have a annoying habit of forgetting that they are factors. E.g.
> x <- factor(LETTERS[1:3])
> c(x, 1)
[1] 1 2 3 1
> c(x,"a")
[1] "1" "2" "3" "a"
However, in order to be compatible with S, a factor "x" needs to
satisfy inherits(x,"factor"). So we also attach "class" of factor to
them as well. Any "class" manipulations use the "class" attribute but
all internal manipulations are based on the "mode".
Ross
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-