Skip to content
Prev 22891 / 63424 Next

c.factor

On Tue, 2006-11-14 at 16:36 +0000, Matthew Dowle wrote:
I'll defer to others as to whether or not there is a basis for c.factor,
however:

c.factor <- function(...)
{
  args <- list(...)

  # this could be optional
  if (!all(sapply(args, is.factor)))
   stop("All arguments must be factors")

  factor(unlist(lapply(args, function(x) as.character(x))))
}


x <- factor(letters[1:5])
y <- factor(letters[4:8])
z <- factor(letters[9:14])
[1] a b c d e
Levels: a b c d e
[1] d e f g h
Levels: d e f g h
[1] i j k l m n
Levels: i j k l m n
[1] a b c d e d e f g h
Levels: a b c d e f g h
[1] a b c d e d e f g h i j k l m n
Levels: a b c d e f g h i j k l m n
Error in c.factor(x, 1:5) : All arguments must be factors


HTH,

Marc Schwartz