R/orderFactors.R

Defines functions orderFactors

Documented in orderFactors

orderFactors <- function(data, ..., values, labels=NULL) {
  .df <- data
  
  .vars <- getVarsList(substitute(list(...)))
  if (is.null(.vars)) {
    msg = "You must provide one or more column(s) name(s)"
    stop(msg)
  }
  
  for (v in .vars) {
    if (!is.null(labels)) {
      .df[,v] <- factor(.df[,v], levels=values, ordered = TRUE, labels=labels)
    } else {
      .df[,v] <- factor(.df[,v], levels=values, ordered = TRUE)
    }
  }
  .df
}

Try the EpiStats package in your browser

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

EpiStats documentation built on Oct. 25, 2023, 5:06 p.m.