R/de_num.R

Defines functions undeutsch_num de_num

Documented in de_num undeutsch_num

#' de_num
#'
#' Convert a number string to the German formatting - converts to character, so be aware!
#' @param x The input, could be a vector or a column
#' @export

de_num <- function(x) {

  require(scales)

  if(class(x)=='numeric') {
    x <- comma(x)
  }
  x <- gsub('.','^',x,fixed=TRUE)
  x <- gsub(',','.',x,fixed=TRUE)
  x <- gsub('^',',',x,fixed=TRUE)

 return(x)

}


#' undeutsch_num
#'
#' Convert a character string with German numbers back to a numeric format readable in R
#' @param x The input, could be a vector or a column
#' @export

undeutsch_num <- function(x) {

  x <- gsub('.','',x,fixed=TRUE)
  x <- as.numeric(gsub(',','.',x,fixed=TRUE))

 return(x)

}
neugelb/neugelbtools documentation built on July 7, 2020, 1:17 a.m.