R/as.fumeric.R

#' converts to factor and then numeric
#'
#' Converts a vector of characters into factors and then converts these into numeric. 
#' 
#' @param x a character vector
#' @param levels the leves to be used in the call to factor
#' 
#' @author Rafael A. Irizarry
#'  
#' @examples
#' 
#' group = c("a","a","b","b")
#' plot(seq_along(group),col=as.fumeric(group))
#' 
as.fumeric <- function(x,levels=unique(x)) {
  if(!is.character(x)) stop("'x' must be a character")
  as.numeric(factor(x,levels=levels))
}

Try the rafalib package in your browser

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

rafalib documentation built on May 1, 2019, 10:26 p.m.