commonSuffix: Longest common suffix

commonSuffixR Documentation

Longest common suffix

Description

Finds and returns the longest suffix 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 NAs before checking for a common suffix

Usage

commonSuffix(x, ignoreCase = FALSE, dropNA = FALSE)

Arguments

x

The strings to find the longest common suffix for.

ignoreCase

Set this true to match suffixes even if they differ in case.

dropNA

Set this true to ignore NAs when searching for a common suffix

Value

The common suffix, if any, or "", if no common suffix can be found.

See Also

commonPrefix

Examples

commonSuffix( c( "ABCDE", "CDE", "cDE" ))
#=> [1] "DE"

commonSuffix( c( "ABC", "abc", "def" ))
#=> [1] ""

commonSuffix( c( "ABCDE", "CDE", "" ))
#=> [1] ""

commonSuffix( c( "ABCDE", "ABCDE", NA ))
#=> [1] NA

commonSuffix( c( "A\u00dfC", "A\u00dfC", "a\u00dfC" ))
#=> [1] "ßC"

commonSuffix( c("ABCDE", "CDE", "cDE" ), ignoreCase= TRUE )
#=> [1] "cde"


jefferys/JefferysRUtils documentation built on Jan. 12, 2024, 9:18 p.m.