rtimesequencehourminute

How do I create a table of a 28 hour clock, by 1 minute intervals?


I am not very familiar with using loops. I am trying to create a table like this: 00:00 00:01 00:02 ... 27:58 27:59 28:00

It is for data that runs into the next day, but is still considered part of the original day.

I tried this:

hh<-c(seq('00','28',1))  
mm<-c(seq('01','60',1))

for (i in (1:29)) {
  int<-paste(hh[i],":",mm)
}
View(int)

but it only does the pastes minutes 1 through 60 onto hour 28: only the 28th hour

I hope this is simpler than I am making it out to be, I don't know how to use the sapply or lapply to do this. Thanks for any help.


Solution

  • You can do this with the help of outer :

    times <- c(t(outer(sprintf('%02d', 0:27),sprintf('%02d', 0:59),paste,sep = ":")))
    #add the last time manually
    times <- c(times, '28:00')
    
    head(times, 8)  
    #[1] "00:00" "00:01" "00:02" "00:03" "00:04" "00:05" "00:06" "00:07"
    tail(times, 8)  
    #[1] "27:53" "27:54" "27:55" "27:56" "27:57" "27:58" "27:59" "28:00"
    

    sprintf appends 0 to a single digit number and we paste every hour (0 to 27) to every minute (0 to 59).