Abbreviate strings to at least minlength characters, such that they remain unique (if they were), unless strict = TRUE.
abbreviate(names.arg, minlength = 4, use.classes = TRUE,
dot = FALSE, strict = FALSE,
method = c("left.kept", "both.sides"), named = TRUE)
| Parameter | Description |
|---|---|
names.arg |
a character vector of names to be abbreviated, or an object to be coerced to a character vector by as.character. |
minlength |
the minimum length of the abbreviations. |
use.classes |
logical: should lowercase characters be removed first? |
dot |
logical: should a dot (".") be appended? |
strict |
logical: should minlength be observed strictly? Note that setting strict = TRUE may return non-unique strings. |
method |
a character string specifying the method used with default "left.kept", see ‘Details’ below. Partial matches allowed. |
named |
logical: should names (with original vector) be returned. |
# NOT RUN {
x <- c("abcd", "efgh", "abce")
abbreviate(x, 2)
abbreviate(x, 2, strict = TRUE) # >> 1st and 3rd are == "ab"
(st.abb <- abbreviate(state.name, 2))
stopifnot(identical(unname(st.abb),
abbreviate(state.name, 2, named=FALSE)))
table(nchar(st.abb)) # out of 50, 3 need 4 letters :
as <- abbreviate(state.name, 3, strict = TRUE)
as[which(as == "Mss")]
# }
# NOT RUN {
## and without distinguishing vowels:
st.abb2 <- abbreviate(state.name, 2, FALSE)
cbind(st.abb, st.abb2)[st.abb2 != st.abb, ]
## 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)
# }