[Rd] levels(f)<-list doesn't work as expected when list is longer than nlevels(f) (PR#1394)

htang@hpl.hp.com htang@hpl.hp.com
Tue, 19 Mar 2002 02:29:14 +0100 (MET)

Full_Name: Hsiu-Khuern Tang
Version: 1.4.1
OS: Linux
Submission from: (NULL) (

Hi all,

   When renaming the levels of a factor f using levels(f)<-list(...), if the
list is longer than the original number of levels in f, the result is wrong.


> f <- factor(c("a","b"))

> levels(f) <- list(C="C", A="a", B="b")

Warning message: 
number of items to replace is not a multiple of replacement length 

> f
[1] C A
Levels:  C A 

The answer should be something like

[1] A B
Levels:  C A B

Hsiu-Khuern Tang.

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