Abbreviate strings to at least
such that they remain unique (if they were),
strict = TRUE.
abbreviate(names.arg, minlength = 4, use.classes = TRUE, dot = FALSE, strict = FALSE, method = c("left.kept", "both.sides"))
- a character vector of names to be abbreviated, or an
object to be coerced to a character vector by
- the minimum length of the abbreviations.
- logical (currently ignored by R).
- logical: should a dot (
".") be appended?
- logical: should
minlengthbe observed strictly? Note that setting
strict = TRUEmay return non-unique strings.
- a character string specifying the method used with default
"left.kept", see Details below. Partial matches allowed.
The default algorithm (
method = "left.kept") used is similar
to that of S. For a single string it works as follows.
First all spaces at the beginning of the string are stripped.
Then (if necessary) any other spaces are stripped.
Next, lower case vowels are removed (starting at the right)
followed by lower case consonants.
Finally if the abbreviation is still longer than
upper case letters are stripped.
Characters are always stripped from the end of the word first.
If an element of
names.arg contains more than one word (words
are separated by space) then at least one letter from each word will be
NA) values are unaltered.
FALSE then the only distinction is to
be between letters and space. This has NOT been implemented.
A character vector containing abbreviations for the strings in its
first argument. Duplicates in the original
names.argwill be given identical abbreviations. If any non-duplicated elements have the same
minlengthabbreviations then, if
method = "both.sides"the basic internal
abbreviate()algorithm is applied to the characterwise reversed strings; if there are still duplicated abbreviations and if
strict = FALSEas by default,
minlengthis incremented by one and new abbreviations are found for those elements only. This process is repeated until all unique elements of
names.arghave unique abbreviations.The character version of
names.argis attached to the returned value as a names argument: no other attributes are retained.
This is really only suitable for English, and does not work correctly with non-ASCII characters in multibyte locales. It will warn if used with non-ASCII characters (and required to reduce the length).
x <- c("abcd", "efgh", "abce") abbreviate(x, 2) abbreviate(x, 2, strict = TRUE) # >> 1st and 3rd are == "ab" (st.abb <- abbreviate(state.name, 2)) table(nchar(st.abb)) # out of 50, 3 need 4 letters : as <- abbreviate(state.name, 3, strict = TRUE) as[which(as == "Mss")] ## method="both.sides" helps: no 4-letters, and only 4 3-letters: st.ab2 <- abbreviate(state.name, 2, method = "both") table(nchar(st.ab2)) ## Compare the two methods: cbind(st.abb, st.ab2)