Hi, I have the following vector of time (Hours, Minutes, Seconds) and the following variable (var1). I want to generate a time variable such as var2. Any ideas on that?
This returns a period object (see the {lubridate} vignette), which is the best you can do with the time column without an accompanying representation of ymd
It depends on the data object and its content. I assume you have a data frame with a class character column Time, you can create var2 using {dplyr}
my_df %>% mutate(var2 = hms(Time)) -> my_df
This will get you a {lubridate} period object. If you need a datetime object instead, you must prepend a date string to the Time column.
Time is capitalized because it's the name of a built-in function, like df and data, and it's good practice to avoid them in naming your own objects because some operations treat the name as the function rather than your object and throw an error message to the effect that something can't be done with a closure.