R/case.R

Defines functions case

Documented in case

case <- function(x, ..., default=NA)
{
  magic <- "....default...."
  alternatives <- c(...,"....default...."=magic)

  x <- as.character(x)
  retval <- factor(
                   x,
                   levels=alternatives,
                   labels=names(alternatives)
                   )
  levels(retval)[length(alternatives)] <- as.character(default)  
  retval[is.na(retval) & !is.na(x)] <- default

  retval
}

Try the gdata package in your browser

Any scripts or data that you put into this service are public.

gdata documentation built on June 6, 2017, 3 a.m.