Remove leading and/or trailing whitespace from character strings.
trimws(x, which = c("both", "left", "right"))
a character vector
a character string specifying whether to remove both
leading and trailing whitespace (default), or only leading
("left"
) or trailing ("right"
). Can be abbreviated.
For portability, ‘whitespace’ is taken as the character class
[ \t\r\n]
(space, horizontal tab, line feed, carriage return).
x <- " Some text. "
x
trimws(x)
trimws(x, "l")
trimws(x, "r")
Run the code above in your browser using DataLab