Learn R Programming

Maeswrap (version 1.4.11)

revchar: Reverse a character string.

Description

Reverses the characters in a character string, unless a vector is supplied, in which case reverses the element of the vector.

Usage

revchar(x)

Arguments

x
A character vector (typically of length 1).

Value

  • A vector.

Details

When a character vector of length > 1 is provided, reverses the elements of the vector, not the characters itself.

References

None.

See Also

rev.default,substr,strsplit

Examples

Run this code
# Take a substring, counting from the end:
substrfromend <- function(x,start,stop)revchar(substr(revchar(x),start,stop))
substrfromend('filename.txt', 1,3)

# Check if a word is a palindrome:
s <- 'saippuakivikauppias'
s == revchar(s)

# A semordnilap:
cat('I am so stressed, I need to eat', revchar('stressed'),'\n')

Run the code above in your browser using DataLab