R/anonomize.R

Defines functions anonomize

Documented in anonomize

##' Create unique anonymous id values
##'
##' Obscure participant id values by replacing them with "anon-1" and
##' so forth.
##'
##' Caution: the true "confidential" names are used as names in the
##' output vector
##' @param x A column of "confidential" names, possibly with repeats
##' @param prefix Character string to use as prefix in result.
##'     Default is "anon"
##' @return Named character vector of anonymized id names.
##' @author Paul Johnson <pauljohn@@ku.edu>
##' x <- c("bill", "bob", "fred", "bill")
##' (anonomize(x, prefix = "id"))
anonomize <- function(x, prefix = "anon"){
    xunique <- unique(x)
    nameunique <- paste0(prefix, "-", seq_along(xunique))
    names(nameunique) <- xunique
    nameunique[x]
}

Try the kutils package in your browser

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

kutils documentation built on Sept. 17, 2023, 5:06 p.m.