[R] Newbie struggling with "factors"
John Fox
jfox at mcmaster.ca
Fri Mar 29 19:24:57 CET 2002
Dear Jonathan and Tom,
At 10:10 AM 3/29/2002 -0500, Jonathan Baron wrote:
>On 03/29/02 05:58, Tom Arnold wrote:
>
> >When I query R about the field, it
> >tells me it is class "factor"
> >
> >> class(n$OSUSE)
> >[1] "factor"
> >> mode(n$OSUSE)
> >[1] "numeric"
>
>I'm surprised at this. I would think it would be character.
Factors are numeric vectors of class factor, with the level information
given by a levels attribute; for example:
> fac <- factor(rep(c("a", "b"), 2))
> fac
[1] a b a b
Levels: a b
> unclass(fac)
[1] 1 2 1 2
attr(,"levels")
[1] "a" "b"
> class(fac)
[1] "factor"
> mode(fac)
[1] "numeric"
>
Regards,
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list