newbe
newbe

Reputation: 15

Converting a column in data set which has time format(hms) into seconds

I am trying to convert a column in dataset that has time format in HMS into seconds.

Below is how my dataset looks like:

Participant Event ID    Event_start Event_time
Joe          1               3         1:49:52
Arya         1               2         1:37:39
Cynthia      1               1         1:40:17

I used this

dataset %>% 
  mutate(Timeinsec = period_to_seconds(hms("Event_time")))

it gives me warning.

Upvotes: 1

Views: 61

Answers (1)

neilfws
neilfws

Reputation: 33802

The warning is because Event_time is quoted. Try it without quotes:

dataset %>%
  mutate(Timeinsec = hms(Event_time))

If you want seconds as an integer, use period_to_seconds:

dataset %>%
  mutate(Sec = period_to_seconds(hms(Event_time)))

Upvotes: 1

Related Questions