Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

shorten

Reduce each in a vector of strings to a given length


Description

This is a simple "chop" at k characters, no fancy truncation at spaces or such. Optionally, this will make unique the resulting truncated strings. That way, truncation at character 4 of "Washington" and "Wash" and "Washingham" will not result in 3 values of "Wash", but rather "Wash", "Wash.1", and "Wash.2"

Usage

shorten(x, k = 20, unique = FALSE)

Arguments

x

character string

k

integer limit on length of string. Default is 20

unique

Default FALSE

Value

vector of character variables no longer than k

Author(s)

Paul Johnson <pauljohn@ku.edu>

Examples

x <- c("Washington", "Washingham", "Washmylaundry")
shorten(x, 4)
shorten(x, 4, unique = TRUE)

kutils

Project Management Tools

v1.70
GPL-2
Authors
Paul Johnson [aut, cre], Benjamin Kite [aut], Charles Redmon [aut], Jared Harpole [ctb], Kenna Whitley [ctb], Po-Yi Chen [ctb], Shadi Pirhosseinloo [ctb]
Initial release
2020-04-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.