The abbreviate
function in R abbreviates string characters to at least minlength
characters. It does so in such a way that they remain unique
(if they were) unless the minlength
value should be observed strictly.
abbreviate(names.arg, minlength = 4, use.classes = TRUE,
dot = FALSE, strict = FALSE,
method = c("left.kept", "both.sides"), named = TRUE)
The abbreviate
function takes the character vector, names.arg
, which takes the vector of names to be abbreviated.
The abbreviate
function takes the following optional parameter values:
minlength
: This represents the minimum length of the abbreviations.use.classes
: This takes a logical value (TRUE
or FALSE
). If TRUE
, the lowercase characters are removed first. If the value is FALSE
, the lowercase characters will be removed after the operation.dot
: This takes a logical value (TRUE
or FALSE
) whether a dot (.
) is appended or not. The default value is TRUE
.strict
: This takes a logical value (TRUE
or FALSE
) whether or not the minlength
is observed strictly.method
: This is a character string that specifies the method used (either to abbreviate from left or right). By default, it uses the "left.kept"
method, which simply means abbreviating from the left side of the string.named
: This takes a logical value (TRUE
or FALSE
) whether the names
with the original vector are returned. The default value is TRUE
.The abbreviate
function returns a character vector containing abbreviations for the character strings in its first argument.
# creating the character vector of namesstates <- c ("Alabama", "Alaska", "Arizona", "Arkansas", "California")# calling the abbreviation() function# minlength of 4, dot = "TRUE", strict = "TRUE"states_abbr = abbreviate(states,4, dot = "TRUE", strict = "TRUE")# printing the abbreviationsstates_abbr
states
containing the words to be abbreviated.abbreviate()
function on the states
variable. The result is assigned to another variable states_abbr
.states_abbr
.