On Sun, 2008-07-13 at 18:47 +0200, Johannes Huesing wrote:
> What is the least surprising way of initializing a factor with 
> predefined levels and with length 0? 
> as.factor(c("eins", "zwei", "drei"))[FALSE] 
> does the job but looks a bit weird.
> 

Notice that one does not need to specify any data as argument 'x' to
factor() because, by default, x = character(). Therefore, we need only
specify the levels we want:

> factor(levels = c("one","two","three"))
factor(0)
Levels: one two three

HTH

G

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to