Learn R Programming

sjPlot (version 1.7)

str_pos: Find partial matching and close distance elements in strings

Description

This function finds the element indices of partial matching or similar strings in a character vector. Can be used to find exact or slightly mistyped elements in a string vector.

Usage

str_pos(searchString, findTerm, maxdist = 3, part.dist.match = 0,
  showProgressBar = FALSE)

Arguments

Value

A numeric vector with index position of elements in searchString that partially match or are similar to findTerm. Returns -1 if no match was found.

See Also

group_str

Examples

Run this code
string <- c("Hello", "Helo", "Hole", "Apple", "Ape", "New", "Old", "System", "Systemic")
str_pos(string, "hel")   # partial match
str_pos(string, "stem")  # partial match
str_pos(string, "R")     # no match
str_pos(string, "saste") # similarity to "System"

# finds two indices, because partial matching now
# also applies to "Systemic"
str_pos(string,
        "sytsme",
        part.dist.match = 1)

# finds nothing
str_pos("We are Sex Pistols!", "postils")
# finds partial matching of similarity
str_pos("We are Sex Pistols!", "postils", part.dist.match = 1)

Run the code above in your browser using DataLab