R/as_numeric.R

Defines functions as_numeric

Documented in as_numeric

#' convert to numeric passing through character for safety
#' @param x vector
#' @param ... additional argument to as.character
#' @examples 
#' # factor with weird levels that we don't want to keep
#' ex <- factor(c(1, 2, 3, 4), levels = c(2, 3, 1, 4)) 
#' ex
#' 
#' # keeps information about the levels, oh no!
#' as.numeric(ex) 
#' 
#' # keeps the labelled values
#' as_numeric(ex)
#' @export
as_numeric <- function(x, ...) {
  suppressWarnings(as.numeric(as.character(x, ...)))
}

Try the PKPDmisc package in your browser

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

PKPDmisc documentation built on April 14, 2020, 5:49 p.m.