Ishan Juneja
Ishan Juneja

Reputation: 421

time conversion to numeric format

I have data in time format, e.g. "15:57:41". After converting it into numeric format using as.numeric() in R, the converted value is 0.6650579. Can anybody please explain the logic in the manual calculation behind this? How is the time getting converted to this numeric value?

Upvotes: 0

Views: 78

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226047

It's a fraction of a day:

library(chron)
as.numeric(times("15:57:41"))
## [1] 0.6650579

Manually convert hours/minutes/seconds to fraction of day:

## (hours + (minutes + seconds/60)/60)/24
(15+(57+41/60)/60)/24
## [1] 0.6650579

Upvotes: 4

Related Questions