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"

Example: Reverse Order of Character String Using stri_reverse() Function of stringi Package

install.packages("stringi")     # Install stringi package
library("stringi")              # Load stringi
stri_reverse(my_string)         # Apply stri_reverse() function
# [1] "gfedc b a"

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed