Generates Class Indicator Matrix from a Factor

DESCRIPTION:

Generates a class indicator function from a given factor.

USAGE:

class.ind(cl)

REQUIRED ARGUMENTS:

cl
factor or vector of classes for cases.

VALUE:

a matrix which is zero except for the column corresponding to the class.

EXAMPLES:

# The function is currently defined as
function(cl)
{
  n <- length(cl)
  cl <- as.factor(cl)
  x <- matrix(0, n, length(levels(cl)) )
  x[(1:n) + n*(unclass(cl)-1)] <- 1
  dimnames(x) <- list(names(cl), levels(cl))
  x
}