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
I don't think rev
quite does it. It reverses the elements of the vector, while the question is how to reverse the elements in the vector.
> nums <- sapply(1:10,function(i)as.numeric(paste(sample(1:9,6,TRUE),collapse="")))
> nums
[1] 912516 568934 693275 835117 155656 378192 343266 685182 298574 666354
> sapply(strsplit(as.character(nums),""), function(i) paste(rev(i),collapse=""))
[1] "615219" "439865" "572396" "711538" "656551" "291873" "662343" "281586" "475892" "453666"