How can you reverse a string of numbers in R?
for instance, I have a vector of about 1000 six digit numbers, and I would like to know if they are palindromes. I wo
There is function in stringi package for that - stri_reverse
stringi
stri_reverse
require(stringi) stri_reverse("123456") ## [1] "654321"
Now palindrome function might as simple as that:
palindrome <- function(x) stri_reverse(x)==x palindrome(c("651156","1234321")) ## [1] TRUE TRUE