[Rd] Why is there no c.factor?

Hadley Wickham hadley at rice.edu
Thu Feb 4 16:53:51 CET 2010


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/



More information about the R-devel mailing list