recode a time variable (format: hh:mm:ss) into a categorical variable

I have a variable named duration.video in the following format hh:mm:ss that I would like to recode into a categorical variable ('Less than 5 minutes', 'between 5 and 30 min', etc.)

Here is my line of code:

video$Duration.video<-as.factor(car::recode(
  video$Duration.video, 
  "00:00:01:00:04:59='Less than 5 minutes';00:05:00:00:30:00='Between 5 and 30 minutes';00:30:01:01:59:59='More than 30 minutes and less than 2h';02:00:00:08:00:00='2h and more'"
))

The code does not work because all the values of the variable are put in one category ('Between 5 and 30 minutes').

I think it's because my variable is in character format but I can't convert it to numeric. And also maybe the format with ":" can be a problem for the recoding in R.

I tried to convert to data.table::ITime but the result remains the same.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation