r - regex remove seconds and miliseconds -


this linked previous question, regex add hypen in dates.

i able remove seconds , milliseconds/change 0 using gsub again well

i.e. somethine

x <- c("20130603 00:00:03.102","20130703 00:01:03.103","20130804 00:03:03.104")   y <- gsub([regex pattern match],[replacement pattern insert hyphen , remove seconds] ,x)  > y [1] "2013-06-03 00:00:00" "2013-07-03 00:01:00" "2013-08-04 00:03:00" 

you can try regex, added bit:

gsub("(\\d{4})(\\d{2})(\\d{2}) (\\d{2}:\\d{2}).*", "\\1-\\2-\\3 \\4:00", subject, perl=true); 

demo on regex101.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -