strtrim {base} | R Documentation |
Trim character strings to specified display widths.
strtrim(x, width)
x |
a character vector, or an object which can be coerced to a
character vector by as.character . |
width |
Positive integer values: recycled to the length of x . |
‘Width’ is interpreted as the display width in a monospaced font. What happens with non-printable characters (such as backspace, tab) is implementation-dependent and may depend on the locale (e.g. they may be included in the count or they may be omitted).
Using this function rather than substr
is important when
there might be double-width characters in character vectors
A character vector of the same length and with the same attributes
as x
(after possible coercion).
strtrim(c("abcdef", "abcdef", "abcdef"), c(1,5,10))