x <- rep("000000",2) y <- c("23/45","67/8") substr(x,1+nchar(x)-nchar(y), nchar(x)) <- y x
--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. David Winsemius <dwinsem...@comcast.net> wrote: Copying list one what was sent in reply. Anybody have a better solution? > On Aug 19, 2011, at 11:57 AM, Vasco Cadavez wrote: > >> Thanks, >> >> A solution can be by substring to remove the / >> then numeric will be ok! What you think? >> >> How can I remove the / > with sub or gsub: > sprintf("%010.0f", as.integer(gsub("/","", c("4/3003","55/333","66/22")) )) [1] "0000043003" "0000055333" "0000006622" -- David. >> >> Thanks >> >> Vasco Cadavez >> >> ----- Menssagem Original ----- >> De: >> "David Winsemius" <dwinsem...@comcast.net> >> >> Para: >> "David Winsemius" <dwinsem...@comcast.net> >> Cópia: >> "Vasco Cadavez" <vcadavez@ipbpt>, <r-help@r-project.org> >> Enviado: >> Fri, 19 Aug 2011 11:51:08 -0400 >> Assunto: >> Re: [R] Leading zeros >> >> >> >> On Aug 19, 2011, at 11:17 AM, David Winsemius wrote: >> >> > >> > On Aug 19, 2011, at 11:12 AM, Vasco Cadavez wrote: >> > >> >> Hello, >> >> I have a dataset with an Id columns like: >> >> 4/3003 >> >> 55/333 >> >> 66/22 >> >> I want to put leading zeros to get: >> >> 00000004/3003 >> >> 000000055/333 >> >> 0000000066/22 >> >> >> >> How can I solve this? >> > >> > ?sprintf >> > ?formatC >> > >> I may have been too quick. Padding with leading zeros using sprintf >> is >> described for numeric but not for character types. There are severa _____________________________________________ R-help@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. [[alternative HTML version deleted]]
______________________________________________ R-help@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.