[R] Factor names & levels

Gabor Grothendieck ggrothendieck at myway.com
Fri Dec 19 06:31:24 CET 2003



names() is only defined for vectors and lists and factors are
neither.  See ?vector and ?names for more info.


---
From: djw1005 at cam.ac.uk 
Subject: [R] Factor names & levels


When I alter the levels of a factor, why does it alter the names too?

f <- factor(c(A="one",B="two",C="one",D="one",E="three"),
            levels=c("one","two","three"))
names(f)

 -- gives [1] "A" "B" "C" "D" "E"

levels(f) <- c("un","deux","trois")
names(f)

 -- gives NULL

I'm using R 1.8.0 for Windows.

Damon.




More information about the R-help mailing list