commonPrefix | R Documentation |
Finds and returns the longest prefix common to all strings in a character
vector. Can be set to ignore case, in which case the returned common string
will be in lower case. If any strings are NA
, this returns NA
unless dropNA= TRUE
is set, which will drop NA
s before
checking for a common prefix.
commonPrefix(x, ignoreCase = FALSE, dropNA = FALSE)
x |
The strings to find the longest common prefix for. |
ignoreCase |
Set this true to match prefixes even if they differ in case. |
dropNA |
Set this true to ignore |
The common prefix, if any, or "", if no common prefix can be found.
commonSuffix
commonPrefix( c( "ABCDE", "ABC", "ABc" ))
#=> [1] "AB"
commonPrefix( c( "ABC", "abc", "def" ))
#=> [1] ""
commonPrefix( c( "ABCDE", "ABC", "" ))
#=> [1] ""
commonPrefix( c( "ABCDE", "ABC", NA ))
#=> [1] NA
commonPrefix( c( "A\u00dfCDE", "A\u00dfC", "A\u00dfc" ))
#=> [1] "Aß"
commonPrefix( c("ABCDE", "ABC", "ABc" ), ignoreCase= TRUE )
#=> [1] "abc"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.