R/roundDF.R

Defines functions roundCol roundDF

Documented in roundDF

roundDF <- function(dat, digits = 3) {
  if(!is.data.frame(dat)) stop("'dat' needs to be a data.frame.")
  if(!is.numeric(digits) || length(digits) != 1) stop("'digits' needs to be a numeric vector of length 1.")

  out <- as.data.frame(lapply(dat, roundCol, digits = digits), stringsAsFactors = FALSE)
  colnames(out) <- colnames(dat)
  rownames(out) <- rownames(dat)
  out
}

roundCol <- function(var, digits) {
  if(!is.numeric(var)) return(var)
  round(var, digits = digits)
}

Try the eatTools package in your browser

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

eatTools documentation built on Nov. 23, 2023, 5:06 p.m.