lubridate::ms - surprising behavior when it comes to parsing seconds

lubridate::ms("9.2", "9.20", "9.02")

[1] "9M 2S" "9M 20S" "9M 2S"

I am puzzled to see that 9.2 is treated the same as 9.02.
My expection would be that 9.2 is interpreted as 9M 20S.
How can i get 9.2 treated as 9 minutes and 20 seconds?
Many thanks.

> lubridate::ms(sprintf("%.2f", as.numeric(c("9.2", "9.20", "9.02"))))
[1] "9M 20S" "9M 20S" "9M 2S" 
2 Likes

Many thanks. Just out of curiosity, would it be fair to call lubridate's behavior a bug? Or is the user simply expected to know about this?

It is expected behavior. The documentation states "recognizes all non-numeric characters except '-' as separators". So it is splitting the first entry into 9 and 2, the second as 9 and 20, and the last as 9 and 2.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.