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" ??? =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
On Wed, 21 May 1997, Kurt Hornik wrote:> Perhaps someone can enlighten me here: > R> x <- factor(LETTERS[1:3]) > [1] "factor" > > S-PLUS has > > x <- factor(LETTERS[1:3]) > > mode(unclass(x)) > [1] "numeric"It's a feature. R has a primitive factor type, S-PLUS doesn't and so loses factorness with unclass(). You can use as.numeric() to coerce to numeric in either system. Thomas Lumley ------------------------------------------------------+------ Biostatistics : "Never attribute to malice what : Uni of Washington : can be adequately explained by : Box 357232 : incompetence" - Hanlon's Razor : Seattle WA 98195-7232 : : ------------------------------------------------------------ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-