0

I have a problem with converting numeric to time in hour:minute:second. I would like to choose 10000 random numbers from uniform distribution and convert them to format h:m:s

X <- runif(10000, 0, 86400)

After this, I have 10000 numbers of seconds within one day. I would like to convert it to format hour:minute:second. For example:

44 ---> 00:00:44
zx8754
  • 52,746
  • 12
  • 114
  • 209
ltrd
  • 326
  • 1
  • 8
  • From linked post: `td <- seconds_to_period(44); sprintf('%02d:%02d:%02d', td@hour, minute(td), second(td))` – zx8754 Oct 05 '17 at 20:30

1 Answers1

4

Use times in the chron package:

library(chron)
times(runif(10))
##  [1] 14:21:18 09:56:58 15:28:11 07:13:17 17:48:09 10:25:43 23:09:23 09:10:28
##  [9] 12:29:03 12:12:11
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341