R + converting a integer to a hh:mm format using regex + gsub -


The interval is a subset of 5 minute intervals for a period of 25 hours

  gt; Interval [1] 45 50 55 100 105 110 115 120 125 130 135 2035 2040 2045 2050 2055 2100 2105 2110 2115 2120 2125 I want to include the :  

put it in a timeline Is that I can convert to a one time format

  & gt; Gsub ('^ ([0- 9] {1,2}) ([0- 9] {2}) $', '\\ 1: \\ 2', interval) [1] "45" "50" "55" "1:00" "1:05" "1:10" "1:15" "1:20" "1:25" "1:30" "1:35" "20:35" "20 : 40 "" 20:45 "[15]" 20:50 "" 20:55 "" 21:00 "" 21:05 "" 21:10 "" 21:15 "" 21:20 "" 21:25 "  

I have almost all work to do for my examples - How do I get it so that it works on numbers " 5 " ... "45" "50" "55"

This duplicate found here but it does not use it

An easy way to do this is to ensure that all inputs are less Is less than 4 characters:

  gsub ('^ ([0-9] {1,2}) ([0-9] {2}) $', '\ \ 1: \ '2', sprintf ('% 04d', interval)) # "00:45" "00:50" "00:55" "01:00" "01:05" "01:10" "01:15 "" 01:20 "" 01:25 "" 01:35 "" 01:35 "" 20:35 "" 20:40 "" 20:45 "" 20:50 "" 20:55 "" 21: 00 "" 21:05 "#" 21:10 "" 21:15 "" 21:20 "" 21:25 "   

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -