R Reverse Order of Characters in String (Example Code)
In this tutorial, I’ll illustrate how to reverse the order of characters in a string in the R programming language.
Creation of Example Data
my_string <- "a b cdefg" # Exemplifying character string my_string # Print character string to RStudio console # [1] "a b cdefg" |
my_string <- "a b cdefg" # Exemplifying character string my_string # Print character string to RStudio console # [1] "a b cdefg"
Example: Reverse Order of Character String Using stri_reverse() Function of stringi Package
install.packages("stringi") # Install stringi package library("stringi") # Load stringi |
install.packages("stringi") # Install stringi package library("stringi") # Load stringi
stri_reverse(my_string) # Apply stri_reverse() function # [1] "gfedc b a" |
stri_reverse(my_string) # Apply stri_reverse() function # [1] "gfedc b a"