R/duplicates.R

#' Find Duplicated Words in a Text String
#' 
#' Find duplicated word/word chunks in a string.  Intended for internal use.
#' @param string A character string.
#' @param threshold An integer of the minimal number of repeats.
#' @return Returns a vector of all duplicated words/chunks.
#' @export
#' @examples
#' \dontrun{
#' duplicates(DATA$state)
#' duplicates(DATA$state[1])
#' }
duplicates <- #used in trans_venn
function(string, threshold=1){
    x<-sort(unlist(strsplit(string, " ")))
    if (threshold > 1) {
        names(table(x))[table(x) >= threshold]
    } else {
        unique(x[duplicated(x)])
    }
}

Try the qdap package in your browser

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

qdap documentation built on May 31, 2023, 5:20 p.m.