R/spss_round.R

Defines functions spss_round

Documented in spss_round

#' A round function that prroximates the way SPSS calculates round
#' (always rounds 0.5*n up)
#'
#' @return A vector of rounded values
#'
#' @param x The vector to round
#' @param n digit number before floating point
#'
#' @examples
#' spss_round(c(0.50,0.49,1.5),0)
#' round(c(0.50,0.49,1.5),0)
#' @export




spss_round = function(x, n=0) {
  posneg = sign(x)
  z = abs(x)*10^n
  z = z + 0.5
  z = trunc(z)
  z = z/10^n
  z*posneg
}
sarid-ins/saridr documentation built on Nov. 10, 2020, 9:07 p.m.