#' Mask Numeric Data
#'
#' \code{mask_numeric} will generate a set of pseudo-random numbers with
#' \emph{n_digits} digits, without repetition. Useful to mask identification
#' numbers such as employee ids, phone numbers, social security numbers.
#' @param x either a vector of length > 1, or a numeric length to output
#' @param n_digits width of the numeric field, large numbers 9+ may fail due to
#' size constraints.
#'
#' @return a vector of length: x, unless x is a vector, then of length(x).
#' @export
#'
#' @examples
#' mask_numeric(rnorm(10), 5)
#' # [1] 80267 74569 51430 66311 77283 91240 20975 71820 47828 41642
#'
#' mask_numeric(3, 5)
#' # [1] 94012 27969 24824
mask_numeric <- function(x, n_digits) {
if(length(x) > 1) {
l <- length(x)
} else l <- x
return(sample(10^n_digits:10^(n_digits-1), l))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.