Dimitri Liakhovitski
2010-Nov-09 17:28 UTC
[R] replaing 1-digit months with 2-digit months in a date
Hello again!
Sorry, if it's a simple question - I am very bad in working with strings.
I have a vector of strings:
x<-c("2000.1","2000.2","2000.10","2000.12")
I'd like to change it so that it the month always has 2 digits, like this:
"2000.01","2000.02","2000.10","2000.12"
Is it possible?
Thanks a lot!
--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com
Henrique Dallazuanna
2010-Nov-09 17:30 UTC
[R] replaing 1-digit months with 2-digit months in a date
Try this:
gsub("\\.(\\d{1}$)", ".0\\1", x)
On Tue, Nov 9, 2010 at 3:28 PM, Dimitri Liakhovitski <
dimitri.liakhovitski@gmail.com> wrote:
> Hello again!
>
> Sorry, if it's a simple question - I am very bad in working with
strings.
>
> I have a vector of strings:
>
x<-c("2000.1","2000.2","2000.10","2000.12")
>
> I'd like to change it so that it the month always has 2 digits, like
this:
>
>
"2000.01","2000.02","2000.10","2000.12"
>
>
> Is it possible?
> Thanks a lot!
> --
> Dimitri Liakhovitski
> Ninah Consulting
> www.ninah.com
>
> ______________________________________________
> 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]