Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Truncated display of hour in R

I would like to create a vector of characters that will display all the possible Hours/Minutes of the day.

Hence, I would like to create a vector that looks like this

hours_mins = c("0:00",  "0:01",....,"5:09",  "5:10",  "5:11",  "5:12",  "5:14",  "5:15",..., "23:58", "23:59" )

However, my problem in creating this vector is that the hour displayed in hours_mins is not in the regular format, i.e. 00:00, or 05:09. Hence, how do I create a vector such as hours_mins with truncated display of the hour?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here’s a base R solution:

sub("^0","", strftime(as.POSIXct("00:00", format="%H:%M")+seq(0,86380,by=60), format="%H:%M") )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading