How can I trim leading and trailing white space?

后端 未结 13 1711
北海茫月
北海茫月 2020-11-22 03:53

I am having some troubles with leading and trailing white space in a data.frame.

For example, I like to take a look at a specific row in a data.fra

13条回答
  •  故里飘歌
    2020-11-22 04:17

    Another option is to use the stri_trim function from the stringi package which defaults to removing leading and trailing whitespace:

    > x <- c("  leading space","trailing space   ")
    > stri_trim(x)
    [1] "leading space"  "trailing space"
    

    For only removing leading whitespace, use stri_trim_left. For only removing trailing whitespace, use stri_trim_right. When you want to remove other leading or trailing characters, you have to specify that with pattern =.

    See also ?stri_trim for more info.

提交回复
热议问题