regex to add hypen in dates
In R I have a character string that looks like the following
x <- c("20130603 00:00:03.102","20130703 00:01:03.103","20130804
00:03:03.104")
I would like to to look like the following by using a single gsub command
(rather than using substr and paste, but my limited regex knowledge is
frustrating me in working out what i need to do to do so:
y <- gsub([REGEX PATTERN TO MATCH],[REPLACEMENT PATTERN TO INSERT HYPHEN] ,x)
> y
[1] "2013-06-03 00:00:03.102" "2013-07-03 00:01:03.103" "2013-08-04
00:03:03.104"
In my actual example, x has a length of several million, so any
microbenchmarking for speed improvements would be helpful.
As always, any help would be greatly appreciated.
No comments:
Post a Comment