How to Reverse a string in R

后端 未结 14 2096
花落未央
花落未央 2020-11-27 03:29

I\'m trying to teach myself R and in doing some sample problems I came across the need to reverse a string.

Here\'s what I\'ve tried so far but the paste operation d

14条回答
  •  我在风中等你
    2020-11-27 04:10

    stringi has had this function for quite a long time:

    stringi::stri_reverse("abcdef")
    ## [1] "fedcba"
    

    Also note that it's vectorized:

    stringi::stri_reverse(c("a", "ab", "abc"))
    ## [1] "a"   "ba"  "cba"
    

提交回复
热议问题