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
This should work in the general case, with any choice of base:
is.palindromic <- function(x, base=10)
{
p <- 0
m <- floor(log(x,base))
sig <- -1
for (i in m:0)
{
tp <- floor(x/base^i)
a <- i+1
b <- m+1-i
if(a==b){c<-0}else{c<-a*b;sig<-sig*-1}
p <- p + tp*c*sig
x <- x - tp*base^i
}
return(!as.logical(p))
}