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 [[alternative HTML version deleted]]
On Dec 20, 2009, at 3:50 PM, 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.s <- c(1101111, 112321) > s / (10 ^ (nchar(s) - 3)) [1] 110.1111 112.3210 See ?nchar > nchar(s) [1] 7 6 HTH, Marc Schwartz
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'ss<-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 ------------------------------
Try this also: sapply(s, function(x)format(x, big.interval = nchar(x) - 3, big.mark = ".")) On Sun, Dec 20, 2009 at 7:50 PM, rusers.sh <rusers.sh at gmail.com> 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 > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O