[R] insert a dot to the numbers

(Ted Harding) Ted.Harding at manchester.ac.uk
Sun Dec 20 23:23:30 CET 2009


On 20-Dec-09 21:50:58, rusers.sh wrote:
> Hi,
>   Anybody can give me some hints on the following problem?
> s<-c(1101111,112321)
>   I want to insert a dot "." after the third number and get the
> following
> results.
> 110.1111
> 112.321
> 
>   Thanks a lot.
> -----------------
> Jane Chang
> Queen's

  s<-c(1101111,112321)
# [A]
  s/(10^(floor(log10(s))-2))
  # [1] 110.1111 112.3210

# [B]
  sub("([0-9]{3})","\\1.",as.character(s))
  [1] "110.1111" "112.321"

# [C]
  as.double(sub("([0-9]{3})","\\1.",as.character(s)))
  # [1] 110.1111 112.3210

Not sure exactly what you are asking; but these should give some ideas.
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 20-Dec-09                                       Time: 22:23:26
------------------------------ XFMail ------------------------------




More information about the R-help mailing list