Re: [R] How do I reverse the digits of a number

2009-10-11 Thread Gabor Grothendieck
On Sun, Oct 11, 2009 at 8:09 AM, Barry Rowlingson wrote: > On Sun, Oct 11, 2009 at 12:53 PM, Gabor Grothendieck > wrote: >> Try this: >> >>> library(tcltk) >>> as.numeric(tcl("string", "reverse", 123)) >> [1] 321 > > The bit where the original poster said 'unknown length' worried me: > >  > as.nu

Re: [R] How do I reverse the digits of a number

2009-10-11 Thread Barry Rowlingson
On Sun, Oct 11, 2009 at 12:53 PM, Gabor Grothendieck wrote: > Try this: > >> library(tcltk) >> as.numeric(tcl("string", "reverse", 123)) > [1] 321 The bit where the original poster said 'unknown length' worried me: > as.numeric(tcl("string", "reverse", 12377656534)) [1] 0.4356568 > as.numeric

Re: [R] How do I reverse the digits of a number

2009-10-11 Thread Gabor Grothendieck
Try this: > library(tcltk) > as.numeric(tcl("string", "reverse", 123)) [1] 321 On Sat, Oct 10, 2009 at 5:37 PM, tom_p wrote: > > Hi All, > > Thanks for your help.  I need to reverse the digits of a number (unknown > lenght).  Example 1234->4321 > > Tom > -- > View this message in context: > ht

[R] How do I reverse the digits of a number

2009-10-10 Thread tom_p
Hi All, Thanks for your help. I need to reverse the digits of a number (unknown lenght). Example 1234->4321 Tom -- View this message in context: http://www.nabble.com/How-do-I-reverse-the-digits-of-a-number-tp25838410p25838410.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] How do I reverse the digits of a number

2009-10-10 Thread Ben Bolker
tom_p wrote: > > Hi All, > > Thanks for your help. I need to reverse the digits of a number (unknown > lenght). Example 1234->4321 > > Tom > > z <- 4321 > as.numeric(paste(rev(strsplit(as.character(z),"")[[1]]),collapse="")) [1] 1234 -- View this message in context: http://www.nabble.