trimws函数——去掉字符串头尾的空格

Remove Leading/Trailing Whitespace
作用:去掉字符串头/尾的空格。

  1. Description

Remove leading and/or trailing whitespace from character strings.

  1. Usage

trimws(x, which = c("both", "left", "right"))

  1. Arguments

x
a character vector
which
a character string specifying whether to remove both leading and trailing whitespace (default), or only leading ("left") or trailing ("right"). Can be abbreviated.
Details

For portability, ‘whitespace’ is taken as the character class [ \t\r\n] (space, horizontal tab, line feed, carriage return).

  1. Examples

     x <- "  Some text. "
     x
     trimws(x)
     trimws(x, "l")
     trimws(x, "r")
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容