getCommonPrefix {Rlibstree} | R Documentation |
This function finds the longest common prefix shared by the input strings. This is different from finding the longest common substring as here we are insisting that this occur at the beginning of each of the strings. This uses a straightforward search, terminating whenever it finds a mismatch in any of the strings.
getCommonPrefix(words, asCharacter = TRUE, na.rm = TRUE)
words |
a character vector containing the strings of interest |
asCharacter |
a logical value which if TRUE means that the
actual prefix is returned. Otherwise, the number of characters in the
prefix is returned and this can be used to compute the substring or
for some other purpose.
|
na.rm |
a logical value indicating whether to remove NA s.
If this is FALSE and there are NA elements in
words , an error is raised. |
If asCharacter
is TRUE
, a character vector giving the
actual prefix. If there is no common prefix, this is the empty
character vector.
If words
is empty, this returns the empty character vector
if asCharacter
is TRUE
and 0 otherwise.
If asCharacter
is FALSE
, this returns a
scalar integer giving the position of the end character
of the common prefix string.
Duncan Temple Lang <duncan@wald.ucdavis.edu>
http://www.omegahat.org/Rlibstree
# The names of enumerated constants in Microsoft Word's # scripting interface. We want to find the common prefix. enumNames = c('wdSummaryModeHighlight', 'wdSummaryModeHideAllButSummary', 'wdSummaryModeInsert', 'wdSummaryModeCreateNew') getCommonPrefix(enumNames)