From hadley at rice.edu  Thu Feb  4 16:53:51 2010
From: hadley at rice.edu (Hadley Wickham)
Date: Thu, 4 Feb 2010 09:53:51 -0600
Subject: [Rd] Why is there no c.factor?
Message-ID: <f8e6ff051002040753x33282f33l78fce9f98dc29ae8@mail.gmail.com>

Hi all,

Is there are reason that there is no c.factor method?  Analogous to
c.Date, I'd expect something like the following to be useful:

c.factor <- function(...) {
  factors <- list(...)
  levels <- unique(unlist(lapply(factors, levels)))
  char <- unlist(lapply(factors, as.character))

  factor(char, levels = levels)
}

c(factor("a"), factor("b"), factor(c("c", "b","a")), factor("d"))
# [1] a b c b a d
# Levels: a b c d

Hadley

-- 
http://had.co.nz/



[Rd] Why is there no c.factor?
Hadley Wickham