Lubridate makes working with time easier, but sometimes it is hard for me to understand.
What I would like to do is to divide a period by integer. For example:
If I run 5 km in 24m:45s what would I run 1 km in?
# period gives me a time object
> as.period(ms("24:30"))
[1] "24M 30S"
But if I try to divide by 5 to get another object in minutes and seconds, it throws an error.
> as.period(ms("24:30"))/5
Error in validObject(.Object) :
invalid class “Period” object: periods must have integer values
What is the cause of this error and how to overcome this?
Many thanks:
Based on answer and comment below this is the solution:
> as.period(as.duration(ms("24:30"))/5)
[1] "4M 54S"
It is necessary due to imprecise nature of period - "periods do not have fixed length".