StrAbbr.Rd
Abbreviate a character vector. The function includes starting from the first character as many characters as there are needed to result in a vector of unique values.
StrAbbr(x, minchar = 1, method = c("left", "fix"))
character vector to be abbreviated
integer, minimal number of characters for the abbreviations.
one out of left
or fix
. While left
restricts the result to as many characters
are needed to ensure uniqueness, does fix
yield a vector with all the elements being as long, as
the the longest needed substring for differentiating the terms.
The abbreviated strings.
StrAbbr(x=levels(d.pizza$driver), minchar=2)
#> [1] "Bu" "Carp" "Cart" "Fa" "Hu" "Mi" "Ta"
StrAbbr(x=levels(d.pizza$driver), minchar=2, method="left")
#> [1] "Bu" "Carp" "Cart" "Fa" "Hu" "Mi" "Ta"
StrAbbr(x=levels(d.pizza$driver), minchar=2, method="fix")
#> [1] "Butc" "Carp" "Cart" "Farm" "Hunt" "Mill" "Tayl"
x <- c("Aaron", "Aaramis", "Berta", "Bello", "Claudia", "Cardinale", "Doretta", "Emilia")
StrAbbr(x, minchar=2, method="left")
#> [1] "Aaro" "Aara" "Ber" "Bel" "Cl" "Ca" "Do" "Em"
StrAbbr(x, minchar=2, method="fix")
#> [1] "Aaro" "Aara" "Bert" "Bell" "Clau" "Card" "Dore" "Emil"