subscript out of bounds - time vector

I'm using the time data type - time vector. I trying to get the seconds, minutes and hours to turn up individual. I know that if use [[1]] it should give me seconds but it gives the whole date and time and when I do [[2]] it comes with an error.

[1] "2021-10-28 12:46:48 BST"
[1] "2021-10-28 12:46:48 BST"
[1] "2021-10-28 12:46:48 BST"
Error in FUN(X[[i]], ...) : subscript out of bounds

This time_vector, has one element so [[2]] should fail.
What is the class / are the classes of this time_vector ?


[1] "POSIXlt" "POSIXt"

Oh great. So it returns values of the class just the same as when we might call Sys.time() to see our systems current time.
There is a helpful package lubridate that make it convenient for me to work with time and dates.
I can do


(mytime <- Sys.time())

(datepart <- date(mytime))
(hourpart <- hour(mytime))
(minpart <- minute(mytime))
(secpart <- second(mytime))

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.