How do I convert a character to a hms data format in R?

Hello All,

I would appreciate anyone's help, I am trying to execute logistic regression and I am stuck at a step in the process.

Upon uploading the data and attempting to run the split test, I noticed that my columns that are actually integers and hms are categorized as characters. So, I attempted to convert each into the appropiate data format and ran into an error.

Here is a sample of the dataframe

> dput(head(dataset2, 10))
structure(list(trip_id = c("21742443", "21742444", "21742445", 
"21742446", "21742447", "21742448", "21742449", "21742450", "21742451", 
"21742452"), start_time = structure(c(1546301077, 1546301293, 
1546301603, 1546301625, 1546301692, 1546301733, 1546301766, 1546301921, 
1546301923, 1546301958), class = c("POSIXct", "POSIXt"), tzone = ""), 
    end_time = structure(c(1546301467, 1546301734, 1546302432, 
    1546303408, 1546302056, 1546301949, 1546301943, 1546302021, 
    1546303650, 1546302294), class = c("POSIXct", "POSIXt"), tzone = ""), 
    bikeid = c(2167L, 4386L, 1524L, 252L, 1170L, 2437L, 2708L, 
    2796L, 6205L, 3939L), tripduration = c(390, 441, 829, 1783, 
    364, 216, 177, 100, 1727, 336), from_station_id = c(199L, 
    44L, 15L, 123L, 173L, 98L, 98L, 211L, 150L, 268L), from_station_name = c("Wabash Ave & Grand Ave", 
    "State St & Randolph St", "Racine Ave & 18th St", "California Ave & Milwaukee Ave", 
    "Mies van der Rohe Way & Chicago Ave", "LaSalle St & Washington St", 
    "LaSalle St & Washington St", "St. Clair St & Erie St", "Fort Dearborn Dr & 31st St", 
    "Lake Shore Dr & North Blvd"), to_station_id = c(84L, 624L, 
    644L, 176L, 35L, 49L, 49L, 142L, 148L, 141L), to_station_name = c("Milwaukee Ave & Grand Ave", 
    "Dearborn St & Van Buren St (*)", "Western Ave & Fillmore St (*)", 
    "Clark St & Elm St", "Streeter Dr & Grand Ave", "Dearborn St & Monroe St", 
    "Dearborn St & Monroe St", "McClurg Ct & Erie St", "State St & 33rd St", 
    "Clark St & Lincoln Ave"), user_type = structure(c(2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("no", "yes"), class = "factor"), 
    gender = c("Male", "Female", "Female", "Male", "Male", "Female", 
    "Male", "Male", "Male", "Male"), birthyear = c(1989L, 1990L, 
    1994L, 1993L, 1994L, 1983L, 1984L, 1990L, 1995L, 1996L), 
    ride_length = c("0:06:30", "0:07:21", "0:13:49", "0:29:43", 
    "0:06:04", "0:03:36", "0:02:57", "0:01:40", "0:28:47", "0:05:36"
    ), day_of_week = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L
    )), row.names = c(NA, 10L), class = "data.frame")

The code I ran:


library(tidyverse)
library(tidymodels)
library(hms)
dataset2 <- read.csv("Bike_Trips_2019.csv")
dataset2$user_type <- factor(dataset2$user_type, levels = c("Customer", "Subscriber"), labels = c("no","yes"))
dataset2$trip_id <- as.character(dataset2$trip_id)
dataset2$start_time <- as.POSIXct(dataset2$start_time)
dataset2$end_time <- as.POSIXct(dataset2$end_time)
dataset2$tripduration <- parse_number(dataset2$tripduration)
dataset2$ride_length <- as_hms(dataset2$ride_length)
set.seed(421)
split <- initial_split(dataset2, prop = 0.8, strata = user_type)
train <-split %>% training()
test <- split %>% testing()

Error Message Received:

! Lossy cast from <character> to <hms> at position(s) 101, 146, 854, 1405, 7935, ... (and 187 more)

How do I best proceed?

Kind Regards,

This works.

library(tidyverse)
library(lubridate)

dataset2 %>% 
  as_tibble() %>% 
  mutate(across(contains("time"), ~as_datetime(.x)))

image

@williaml The lubridate code worked by itself

lubridate::hms(dataset2$ride_length)

Output:

 library(hms)
> lubridate::hms(dataset2$ride_length)
   [1] "6M 30S"      "7M 21S"      "13M 49S"     "29M 43S"     "6M 4S"      
   [6] "3M 36S"      "2M 57S"      "1M 40S"      "28M 47S"     "5M 36S"     
  [11] "14M 46S"     "10M 53S"     "10M 1S"      "9M 22S"      "15M 6S"     
  [16] "14M 52S"     "6M 47S"      "22M 36S"     "1M 42S"      "38M 53S"    
  [21] "16M 0S"      "38M 21S"     "19M 28S"     "7M 54S"      "17M 16S"    
  [26] "3M 50S"      "12M 27S"     "11M 51S"     "9M 13S"      "8M 41S"     
  [31] "32M 14S"     "4M 15S"      "5M 7S"       "7M 7S"       "10M 55S"    
  [36] "2M 54S"      "2M 0S"       "17M 24S"     "6M 44S"      "9M 1S"      
  [41] "8M 55S"      "19M 7S"      "4M 38S"      "15M 9S"      "6M 23S"     
  [46] "17M 39S"     "13M 33S"     "7M 46S"      "21M 40S"     "8M 13S"     
  [51] "18M 22S"     "7M 50S"      "16M 7S"      "16M 18S"     "22M 46S"    
  [56] "22M 44S"     "3M 42S"      "9M 7S"       "44M 34S"     "7M 3S"      
  [61] "39M 21S"     "19M 29S"     "14M 13S"     "16M 17S"     "2M 51S"     
  [66] "5M 23S"      "9M 2S"       "14M 18S"     "4M 16S"      "10M 59S"    
  [71] "7M 18S"      "8M 29S"      "6M 36S"      "6M 32S"      "15M 23S"    
  [76] "7M 33S"      "7M 27S"      "21M 23S"     "20M 59S"     "10M 27S"    
  [81] "8M 44S"      "33M 18S"     "8M 17S"      "8M 10S"      "9M 1S"      
  [86] "28M 15S"     "2M 57S"      "5M 2S"       "3M 48S"      "16M 8S"     
  [91] "4M 0S"       "5M 15S"      "38M 28S"     "2M 56S"      "9M 19S"     
  [96] "5M 39S"      "21M 42S"     "10M 39S"     "5M 24S"      "14M 23S"    
 [101] "31H 14M 26S" "5M 7S"       "1M 53S"      "29M 22S"     "30M 38S"    
 [106] "3M 0S"       "13M 19S"     "5M 57S"      "5M 25S"      "11M 22S"    
 [111] "10M 52S"     "5M 49S"      "3M 27S"      "3M 34S"      "9M 21S"     
 [116] "1M 56S"      "17M 37S"     "25M 38S"     "35M 20S"     "21M 20S"    
 [121] "2M 25S"      "45M 36S"     "7M 1S"       "5M 52S"      "4M 42S"     
 [126] "6M 37S"      "23M 45S"     "10M 3S"      "10M 52S"     "3M 27S"     
 [131] "5M 28S"      "17M 37S"     "44M 29S"     "11M 16S"     "2M 4S"      
 [136] "2M 31S"      "9M 50S"      "39M 2S"      "9M 11S"      "2M 46S"     
 [141] "34M 57S"     "8M 25S"      "4M 32S"      "7M 19S"      "4M 27S"     
 [146] "26H 30M 30S" "24M 24S"     "4M 7S"       "3M 52S"      "4M 14S"     
 [151] "3M 56S"      "3M 1S"       "2M 36S"      "7M 18S"      "10M 0S"     
 [156] "22M 22S"     "6M 14S"      "10M 12S"     "3M 7S"       "2M 29S"     
 [161] "7M 58S"      "11M 0S"      "3M 19S"      "5M 29S"      "8M 5S"      
 [166] "25M 12S"     "11M 3S"      "8M 2S"       "5M 33S"      "21M 5S"     
 [171] "5M 38S"      "21M 15S"     "8M 57S"      "6M 51S"      "8M 6S"      
 [176] "2M 4S"       "8M 13S"      "10M 49S"     "9M 40S"      "10M 7S"     
 [181] "20M 20S"     "13M 38S"     "12M 40S"     "28M 39S"     "4M 21S"     
 [186] "14M 54S"     "37M 10S"     "5M 4S"       "13M 26S"     "35M 19S"    
 [191] "15M 37S"     "3M 19S"      "44M 57S"     "5M 50S"      "31M 57S"    
 [196] "7M 19S"      "6M 34S"      "4M 43S"      "2M 34S"      "13M 31S"    
 [201] "11M 19S"     "15M 8S"      "7M 13S"      "4M 50S"      "37M 19S"    
 [206] "11M 41S"     "22M 24S"     "19M 33S"     "4M 51S"      "12M 53S"    
 [211] "4M 28S"      "8M 31S"      "3M 42S"      "1M 53S"      "2M 50S"     
 [216] "11M 16S"     "13M 58S"     "4M 41S"      "9M 42S"      "5M 3S"      
 [221] "4M 45S"      "5M 41S"      "9M 29S"      "12M 43S"     "6M 10S"     
 [226] "5M 18S"      "5M 36S"      "6M 49S"      "4M 16S"      "1H 1M 18S"  
 [231] "38M 53S"     "2M 44S"      "4M 12S"      "7M 41S"      "3M 48S"     
 [236] "5M 7S"       "16M 55S"     "15M 7S"      "11M 39S"     "5M 6S"      
 [241] "2M 46S"      "7M 28S"      "10M 4S"      "2M 52S"      "7M 51S"     
 [246] "29M 46S"     "1M 13S"      "7M 59S"      "18M 58S"     "12M 3S"     
 [251] "5M 39S"      "26M 19S"     "32M 25S"     "1M 52S"      "36M 15S"    
 [256] "4M 54S"      "16M 15S"     "3M 30S"      "3M 16S"      "2M 30S"     
 [261] "11M 23S"     "15M 18S"     "4M 5S"       "9M 10S"      "4M 28S"     
 [266] "9M 3S"       "19M 7S"      "10M 16S"     "20M 26S"     "8M 21S"     
 [271] "2M 41S"      "6M 28S"      "7M 16S"      "6M 7S"       "11M 3S"     
 [276] "7M 49S"      "13M 29S"     "13M 11S"     "4M 46S"      "9M 25S"     
 [281] "10M 47S"     "10M 7S"      "4M 2S"       "5M 22S"      "23M 40S"    
 [286] "4M 3S"       "10M 13S"     "6M 7S"       "7M 11S"      "1M 56S"     
 [291] "37M 29S"     "10M 18S"     "10M 4S"      "14M 17S"     "2M 12S"     
 [296] "11M 13S"     "6M 56S"      "16M 15S"     "2M 57S"      "33M 19S"    
 [301] "2H 18M 11S"  "7M 10S"      "1M 57S"      "8M 54S"      "2M 54S"     
 [306] "5M 55S"      "11M 5S"      "7M 27S"      "3M 58S"      "19M 54S"    
 [311] "16M 54S"     "23H 45M 54S" "4M 49S"      "5M 43S"      "13M 15S"    
 [316] "3M 15S"      "10M 35S"     "6M 32S"      "2M 57S"      "16M 11S"    
 [321] "4M 7S"       "5M 2S"       "10M 3S"      "7M 44S"      "12M 17S"    
 [326] "4M 57S"      "12M 46S"     "5M 56S"      "29M 55S"     "8M 16S"     
 [331] "28M 29S"     "8M 58S"      "9M 2S"       "11M 47S"     "13M 32S"    
 [336] "17M 46S"     "14M 52S"     "3M 56S"      "26M 7S"      "5M 45S"     
 [341] "9M 43S"      "9M 4S"       "18M 22S"     "8M 56S"      "2M 3S"      
 [346] "6M 41S"      "10M 13S"     "16M 9S"      "15M 17S"     "21M 36S"    
 [351] "10M 44S"     "8M 13S"      "16M 26S"     "1M 30S"      "4M 44S"     
 [356] "16M 9S"      "7M 10S"      "7M 10S"      "4M 53S"      "3M 59S"     
 [361] "3M 50S"      "14M 10S"     "7M 28S"      "2M 28S"      "2M 41S"     
 [366] "6M 49S"      "5M 24S"      "7M 36S"      "8M 3S"       "25M 53S"    
 [371] "4M 21S"      "4M 56S"      "18M 48S"     "5M 34S"      "5M 22S"     
 [376] "4M 49S"      "4M 40S"      "21M 7S"      "4M 32S"      "11M 37S"    
 [381] "4M 48S"      "8M 56S"      "4M 41S"      "7M 11S"      "38M 7S"     
 [386] "37M 17S"     "31M 22S"     "5M 46S"      "7M 12S"      "31M 22S"    
 [391] "30M 34S"     "2H 5M 22S"   "30M 35S"     "1H 54M 57S"  "2M 53S"     
 [396] "9M 28S"      "3M 19S"      "22M 10S"     "6M 22S"      "7M 55S"     
 [401] "7M 21S"      "8M 51S"      "10M 11S"     "2M 18S"      "18M 22S"    
 [406] "8M 4S"       "10M 17S"     "26M 47S"     "4M 57S"      "28M 23S"    
 [411] "14M 14S"     "7M 13S"      "11M 19S"     "10M 27S"     "2M 41S"     
 [416] "2M 53S"      "11M 45S"     "3M 28S"      "18M 52S"     "13M 0S"     
 [421] "15M 43S"     "20M 12S"     "8M 4S"       "4M 28S"      "2M 46S"     
 [426] "4M 41S"      "5M 50S"      "29M 52S"     "24M 12S"     "36M 25S"    
 [431] "5M 45S"      "4M 17S"      "14M 2S"      "18M 34S"     "11M 50S"    
 [436] "6M 10S"      "12M 38S"     "13M 41S"     "7M 20S"      "21M 2S"     
 [441] "29M 24S"     "29M 24S"     "18M 51S"     "12M 35S"     "2M 25S"     
 [446] "6M 2S"       "6M 53S"      "29M 42S"     "16M 10S"     "3M 42S"     
 [451] "5M 23S"      "2H 36M 31S"  "8M 48S"      "12M 35S"     "7M 44S"     
 [456] "21M 55S"     "5M 40S"      "7M 55S"      "3M 53S"      "5M 4S"      
 [461] "6M 39S"      "1M 46S"      "6M 24S"      "9M 1S"       "17M 2S"     
 [466] "5M 30S"      "13M 20S"     "5M 13S"      "6M 43S"      "5M 24S"     
 [471] "18M 36S"     "15M 53S"     "5M 21S"      "6M 26S"      "5M 7S"      
 [476] "3M 32S"      "12M 1S"      "4M 50S"      "4M 47S"      "6M 9S"      
 [481] "6M 1S"       "19M 30S"     "7M 54S"      "7M 21S"      "1H 58M 49S" 
 [486] "11M 57S"     "4M 37S"      "6M 38S"      "13M 36S"     "2M 54S"     
 [491] "16M 34S"     "18M 42S"     "2M 41S"      "3M 6S"       "21M 39S"    
 [496] "8M 54S"      "2M 36S"      "24M 4S"      "23M 50S"     "16M 46S"    
 [501] "8M 54S"      "4M 40S"      "12M 44S"     "17M 28S"     "6M 6S"      
 [506] "17M 5S"      "2M 41S"      "7M 42S"      "5M 25S"      "17M 13S"    
 [511] "17M 18S"     "9M 31S"      "7M 29S"      "19M 16S"     "7M 36S"     
 [516] "5M 32S"      "5M 32S"      "21H 12M 30S" "3M 20S"      "9M 19S"     
 [521] "18H 30M 22S" "10M 6S"      "11M 26S"     "11M 56S"     "13M 49S"    
 [526] "8M 20S"      "47M 12S"     "17M 40S"     "4M 3S"       "2H 53M 17S" 
 [531] "8M 45S"      "7M 29S"      "15M 33S"     "54M 21S"     "8M 58S"     
 [536] "54M 31S"     "33M 10S"     "6M 6S"       "8M 35S"      "7M 42S"     
 [541] "15M 59S"     "7M 8S"       "22M 58S"     "3M 21S"      "5M 7S"      
 [546] "3M 5S"       "13M 27S"     "25M 39S"     "10M 51S"     "9M 0S"      
 [551] "10M 28S"     "9M 59S"      "6M 4S"       "6M 11S"      "6M 47S"     
 [556] "12M 23S"     "16M 27S"     "18M 29S"     "12M 40S"     "3M 26S"     
 [561] "20M 23S"     "8M 42S"      "4M 31S"      "6M 59S"      "10M 47S"    
 [566] "6M 13S"      "8M 19S"      "7M 21S"      "13M 2S"      "6M 38S"     
 [571] "56M 40S"     "5M 50S"      "3M 35S"      "7M 1S"       "6M 40S"     
 [576] "3M 38S"      "14M 31S"     "8M 31S"      "12M 6S"      "7M 50S"     
 [581] "16M 22S"     "21M 28S"     "21M 36S"     "8M 11S"      "16M 25S"    
 [586] "5M 53S"      "30M 16S"     "9M 39S"      "9M 50S"      "6M 1S"      
 [591] "7M 28S"      "6M 58S"      "6M 36S"      "10M 47S"     "20M 31S"    
 [596] "4M 18S"      "23M 43S"     "3M 43S"      "3M 43S"      "15M 44S"    
 [601] "15M 21S"     "11M 44S"     "5M 9S"       "28M 19S"     "26M 12S"    
 [606] "8M 32S"      "2H 12M 37S"  "27M 29S"     "5M 14S"      "9M 38S"     
 [611] "9M 38S"      "25M 2S"      "4M 24S"      "5M 43S"      "8M 40S"     
 [616] "13M 10S"     "13M 2S"      "9M 12S"      "13M 55S"     "3M 48S"     
 [621] "1M 18S"      "26M 6S"      "13M 12S"     "6M 28S"      "6M 5S"      
 [626] "11M 15S"     "6M 48S"      "10M 58S"     "5M 40S"      "9M 18S"     
 [631] "2M 24S"      "12M 1S"      "8M 5S"       "11M 58S"     "4H 35M 10S" 
 [636] "20M 12S"     "17M 46S"     "13M 14S"     "15M 49S"     "10M 32S"    
 [641] "9M 19S"      "5M 23S"      "4M 27S"      "12M 53S"     "11M 52S"    
 [646] "17M 59S"     "13M 18S"     "9M 22S"      "6M 12S"      "13M 48S"    
 [651] "5M 27S"      "16M 22S"     "22M 31S"     "6M 22S"      "4M 20S"     
 [656] "15M 43S"     "10M 2S"      "15M 0S"      "22M 13S"     "6M 46S"     
 [661] "10M 6S"      "14M 53S"     "8M 28S"      "8M 25S"      "5M 15S"     
 [666] "9M 7S"       "10M 1S"      "8M 55S"      "6M 2S"       "2M 37S"     
 [671] "2M 44S"      "13M 3S"      "14M 27S"     "23M 23S"     "7M 36S"     
 [676] "10M 46S"     "18M 44S"     "4M 45S"      "8M 19S"      "25M 20S"    
 [681] "5M 2S"       "5M 58S"      "11M 55S"     "4M 39S"      "10M 15S"    
 [686] "4M 23S"      "2M 22S"      "2M 44S"      "13M 53S"     "5M 55S"     
 [691] "8M 8S"       "9M 10S"      "18M 1S"      "19M 43S"     "18M 39S"    
 [696] "20M 24S"     "3M 37S"      "28M 0S"      "7M 12S"      "6M 13S"     
 [701] "7M 11S"      "5M 38S"      "21M 44S"     "9M 16S"      "3M 47S"     
 [706] "2M 47S"      "9M 53S"      "5M 54S"      "4M 25S"      "19M 40S"    
 [711] "9M 24S"      "4M 33S"      "1M 58S"      "19M 16S"     "3M 27S"     
 [716] "22M 20S"     "8M 35S"      "6M 20S"      "25M 3S"      "5M 31S"     
 [721] "13M 56S"     "27M 27S"     "27M 28S"     "10M 13S"     "36M 53S"    
 [726] "12M 17S"     "43M 43S"     "43M 38S"     "6M 28S"      "42M 53S"    
 [731] "17M 37S"     "17M 10S"     "6M 40S"      "9M 11S"      "5M 9S"      
 [736] "1M 54S"      "24M 10S"     "2M 28S"      "4M 10S"      "23M 11S"    
 [741] "14M 20S"     "18M 23S"     "5M 19S"      "5M 38S"      "15M 5S"     
 [746] "18M 36S"     "2M 15S"      "8M 12S"      "3M 39S"      "16M 4S"     
 [751] "6M 47S"      "7M 22S"      "4M 42S"      "1M 10S"      "12M 5S"     
 [756] "11M 25S"     "39M 35S"     "11M 56S"     "27M 59S"     "13M 53S"    
 [761] "13M 27S"     "5M 1S"       "17M 37S"     "18M 20S"     "5M 6S"      
 [766] "19M 48S"     "4M 26S"      "10M 7S"      "9M 11S"      "34M 53S"    
 [771] "34M 30S"     "4M 14S"      "41M 40S"     "1M 53S"      "8M 51S"     
 [776] "7M 22S"      "5M 15S"      "11M 49S"     "18M 22S"     "4M 53S"     
 [781] "7M 52S"      "4M 52S"      "9M 49S"      "20M 39S"     "5M 11S"     
 [786] "11M 39S"     "25M 30S"     "25M 20S"     "25M 28S"     "22M 37S"    
 [791] "25M 4S"      "9M 6S"       "9M 25S"      "14M 45S"     "4M 51S"     
 [796] "5M 44S"      "6M 10S"      "5M 21S"      "22M 10S"     "1H 47M 23S" 
 [801] "6M 20S"      "26M 53S"     "15M 38S"     "29M 22S"     "7M 13S"     
 [806] "13M 54S"     "9M 49S"      "6M 13S"      "13M 37S"     "3M 21S"     
 [811] "4M 12S"      "3M 9S"       "6M 47S"      "7M 35S"      "7M 41S"     
 [816] "28M 23S"     "11M 41S"     "16M 12S"     "8M 51S"      "16M 35S"    
 [821] "29M 47S"     "31M 20S"     "10M 42S"     "31M 14S"     "12M 3S"     
 [826] "39M 44S"     "9M 3S"       "39M 30S"     "21M 26S"     "11M 3S"     
 [831] "3M 28S"      "10M 14S"     "3M 39S"      "5M 7S"       "5M 9S"      
 [836] "18M 39S"     "4M 5S"       "1M 1S"       "38M 27S"     "1H 20M 37S" 
 [841] "1H 21M 4S"   "7M 0S"       "7M 42S"      "4M 53S"      "3M 27S"     
 [846] "7M 11S"      "3M 55S"      "12M 26S"     "6M 43S"      "1M 58S"     
 [851] "5M 8S"       "4M 20S"      "12M 59S"     "71H 23M 36S" "13M 29S"    
 [856] "3M 59S"      "12M 14S"     "8M 45S"      "8M 41S"      "24M 34S"    
 [861] "22M 32S"     "8M 50S"      "16M 13S"     "15M 8S"      "15M 2S"     
 [866] "3M 48S"      "7M 0S"       "6M 38S"      "29M 13S"     "5M 37S"     
 [871] "10M 5S"      "10M 2S"      "5M 12S"      "5M 54S"      "6M 29S"     
 [876] "11M 45S"     "9M 46S"      "5M 3S"       "3M 17S"      "6M 33S"     
 [881] "30M 5S"      "3M 12S"      "5M 4S"       "22M 34S"     "11M 19S"    
 [886] "18M 48S"     "6M 34S"      "11M 9S"      "11M 10S"     "9M 3S"      
 [891] "8M 29S"      "4M 33S"      "1M 22S"      "15M 30S"     "1M 33S"     
 [896] "11M 20S"     "2M 23S"      "28M 17S"     "25M 41S"     "5M 54S"     
 [901] "20M 12S"     "7M 11S"      "9M 55S"      "1M 26S"      "4M 20S"     
 [906] "1M 34S"      "5M 21S"      "19M 25S"     "11M 6S"      "5M 59S"     
 [911] "4M 35S"      "5M 5S"       "9M 2S"       "9M 56S"      "32M 50S"    
 [916] "15M 27S"     "5M 2S"       "22M 12S"     "4M 49S"      "10M 15S"    
 [921] "3M 15S"      "9M 54S"      "18M 19S"     "8M 3S"       "5M 20S"     
 [926] "4M 14S"      "7M 21S"      "6M 5S"       "5M 45S"      "15M 18S"    
 [931] "13M 9S"      "3M 43S"      "1M 18S"      "2M 38S"      "6M 13S"     
 [936] "6M 52S"      "4M 40S"      "18M 52S"     "3M 44S"      "6M 22S"     
 [941] "8M 51S"      "10M 24S"     "32M 8S"      "15M 37S"     "14M 7S"     
 [946] "9M 3S"       "6M 31S"      "18M 19S"     "13M 32S"     "10M 24S"    
 [951] "16M 2S"      "2M 49S"      "9M 54S"      "9M 3S"       "14M 3S"     
 [956] "14M 12S"     "8M 46S"      "6M 33S"      "3M 32S"      "29M 10S"    
 [961] "4M 41S"      "6M 41S"      "11M 48S"     "5M 19S"      "5M 14S"     
 [966] "52M 15S"     "13M 27S"     "50M 52S"     "10M 25S"     "1M 20S"     
 [971] "26M 1S"      "16M 5S"      "9M 17S"      "8M 2S"       "4M 54S"     
 [976] "6M 21S"      "3M 1S"       "12M 34S"     "12M 24S"     "14M 20S"    
 [981] "5M 54S"      "9M 28S"      "1M 15S"      "21M 47S"     "11M 41S"    
 [986] "8M 0S"       "5M 51S"      "6M 52S"      "4M 17S"      "1H 7M 14S"  
 [991] "13M 8S"      "4M 21S"      "2M 17S"      "3M 30S"      "8M 34S"     
 [996] "6M 32S"      "5M 17S"      "17M 54S"     "9M 58S"      "10M 13S"    
 [ reached getOption("max.print") -- omitted 364069 entries ]
> dataset2 <- read.csv("Bike_Trips_2019.csv")
> dataset2$user_type <- factor(dataset2$user_type, levels = c("Customer", "Subscriber"), labels = c("no","yes"))
> dataset2$trip_id <- as.character(dataset2$trip_id)
> dataset2$start_time <- as.POSIXct(dataset2$start_time)
> dataset2$end_time <- as.POSIXct(dataset2$end_time)
> dataset2$tripduration <- parse_number(dataset2$tripduration)
> dataset2$ride_length <- lubridate::hms(ride_length) |>
+   hms::hms()
Error: object 'ride_length' not found
> lubridate::hms(dataset2$ride_length)
   [1] "6M 30S"      "7M 21S"      "13M 49S"     "29M 43S"     "6M 4S"      
   [6] "3M 36S"      "2M 57S"      "1M 40S"      "28M 47S"     "5M 36S"     
  [11] "14M 46S"     "10M 53S"     "10M 1S"      "9M 22S"      "15M 6S"     
  [16] "14M 52S"     "6M 47S"      "22M 36S"     "1M 42S"      "38M 53S"    
  [21] "16M 0S"      "38M 21S"     "19M 28S"     "7M 54S"      "17M 16S"    
  [26] "3M 50S"      "12M 27S"     "11M 51S"     "9M 13S"      "8M 41S"     
  [31] "32M 14S"     "4M 15S"      "5M 7S"       "7M 7S"       "10M 55S"    
  [36] "2M 54S"      "2M 0S"       "17M 24S"     "6M 44S"      "9M 1S"      
  [41] "8M 55S"      "19M 7S"      "4M 38S"      "15M 9S"      "6M 23S"     
  [46] "17M 39S"     "13M 33S"     "7M 46S"      "21M 40S"     "8M 13S"     
  [51] "18M 22S"     "7M 50S"      "16M 7S"      "16M 18S"     "22M 46S"    
  [56] "22M 44S"     "3M 42S"      "9M 7S"       "44M 34S"     "7M 3S"      
  [61] "39M 21S"     "19M 29S"     "14M 13S"     "16M 17S"     "2M 51S"     
  [66] "5M 23S"      "9M 2S"       "14M 18S"     "4M 16S"      "10M 59S"    
  [71] "7M 18S"      "8M 29S"      "6M 36S"      "6M 32S"      "15M 23S"    
  [76] "7M 33S"      "7M 27S"      "21M 23S"     "20M 59S"     "10M 27S"    
  [81] "8M 44S"      "33M 18S"     "8M 17S"      "8M 10S"      "9M 1S"      
  [86] "28M 15S"     "2M 57S"      "5M 2S"       "3M 48S"      "16M 8S"     
  [91] "4M 0S"       "5M 15S"      "38M 28S"     "2M 56S"      "9M 19S"     
  [96] "5M 39S"      "21M 42S"     "10M 39S"     "5M 24S"      "14M 23S"    
 [101] "31H 14M 26S" "5M 7S"       "1M 53S"      "29M 22S"     "30M 38S"    
 [106] "3M 0S"       "13M 19S"     "5M 57S"      "5M 25S"      "11M 22S"    
 [111] "10M 52S"     "5M 49S"      "3M 27S"      "3M 34S"      "9M 21S"     
 [116] "1M 56S"      "17M 37S"     "25M 38S"     "35M 20S"     "21M 20S"    
 [121] "2M 25S"      "45M 36S"     "7M 1S"       "5M 52S"      "4M 42S"     
 [126] "6M 37S"      "23M 45S"     "10M 3S"      "10M 52S"     "3M 27S"     
 [131] "5M 28S"      "17M 37S"     "44M 29S"     "11M 16S"     "2M 4S"      
 [136] "2M 31S"      "9M 50S"      "39M 2S"      "9M 11S"      "2M 46S"     
 [141] "34M 57S"     "8M 25S"      "4M 32S"      "7M 19S"      "4M 27S"     
 [146] "26H 30M 30S" "24M 24S"     "4M 7S"       "3M 52S"      "4M 14S"     
 [151] "3M 56S"      "3M 1S"       "2M 36S"      "7M 18S"      "10M 0S"     
 [156] "22M 22S"     "6M 14S"      "10M 12S"     "3M 7S"       "2M 29S"     
 [161] "7M 58S"      "11M 0S"      "3M 19S"      "5M 29S"      "8M 5S"      
 [166] "25M 12S"     "11M 3S"      "8M 2S"       "5M 33S"      "21M 5S"     
 [171] "5M 38S"      "21M 15S"     "8M 57S"      "6M 51S"      "8M 6S"      
 [176] "2M 4S"       "8M 13S"      "10M 49S"     "9M 40S"      "10M 7S"     
 [181] "20M 20S"     "13M 38S"     "12M 40S"     "28M 39S"     "4M 21S"     
 [186] "14M 54S"     "37M 10S"     "5M 4S"       "13M 26S"     "35M 19S"    
 [191] "15M 37S"     "3M 19S"      "44M 57S"     "5M 50S"      "31M 57S"    
 [196] "7M 19S"      "6M 34S"      "4M 43S"      "2M 34S"      "13M 31S"    
 [201] "11M 19S"     "15M 8S"      "7M 13S"      "4M 50S"      "37M 19S"    
 [206] "11M 41S"     "22M 24S"     "19M 33S"     "4M 51S"      "12M 53S"    
 [211] "4M 28S"      "8M 31S"      "3M 42S"      "1M 53S"      "2M 50S"     
 [216] "11M 16S"     "13M 58S"     "4M 41S"      "9M 42S"      "5M 3S"      
 [221] "4M 45S"      "5M 41S"      "9M 29S"      "12M 43S"     "6M 10S"     
 [226] "5M 18S"      "5M 36S"      "6M 49S"      "4M 16S"      "1H 1M 18S"  
 [231] "38M 53S"     "2M 44S"      "4M 12S"      "7M 41S"      "3M 48S"     
 [236] "5M 7S"       "16M 55S"     "15M 7S"      "11M 39S"     "5M 6S"      
 [241] "2M 46S"      "7M 28S"      "10M 4S"      "2M 52S"      "7M 51S"     
 [246] "29M 46S"     "1M 13S"      "7M 59S"      "18M 58S"     "12M 3S"     
 [251] "5M 39S"      "26M 19S"     "32M 25S"     "1M 52S"      "36M 15S"    
 [256] "4M 54S"      "16M 15S"     "3M 30S"      "3M 16S"      "2M 30S"     
 [261] "11M 23S"     "15M 18S"     "4M 5S"       "9M 10S"      "4M 28S"     
 [266] "9M 3S"       "19M 7S"      "10M 16S"     "20M 26S"     "8M 21S"     
 [271] "2M 41S"      "6M 28S"      "7M 16S"      "6M 7S"       "11M 3S"     
 [276] "7M 49S"      "13M 29S"     "13M 11S"     "4M 46S"      "9M 25S"     
 [281] "10M 47S"     "10M 7S"      "4M 2S"       "5M 22S"      "23M 40S"    
 [286] "4M 3S"       "10M 13S"     "6M 7S"       "7M 11S"      "1M 56S"     
 [291] "37M 29S"     "10M 18S"     "10M 4S"      "14M 17S"     "2M 12S"     
 [296] "11M 13S"     "6M 56S"      "16M 15S"     "2M 57S"      "33M 19S"    
 [301] "2H 18M 11S"  "7M 10S"      "1M 57S"      "8M 54S"      "2M 54S"     
 [306] "5M 55S"      "11M 5S"      "7M 27S"      "3M 58S"      "19M 54S"    
 [311] "16M 54S"     "23H 45M 54S" "4M 49S"      "5M 43S"      "13M 15S"    
 [316] "3M 15S"      "10M 35S"     "6M 32S"      "2M 57S"      "16M 11S"    
 [321] "4M 7S"       "5M 2S"       "10M 3S"      "7M 44S"      "12M 17S"    
 [326] "4M 57S"      "12M 46S"     "5M 56S"      "29M 55S"     "8M 16S"     
 [331] "28M 29S"     "8M 58S"      "9M 2S"       "11M 47S"     "13M 32S"    
 [336] "17M 46S"     "14M 52S"     "3M 56S"      "26M 7S"      "5M 45S"     
 [341] "9M 43S"      "9M 4S"       "18M 22S"     "8M 56S"      "2M 3S"      
 [346] "6M 41S"      "10M 13S"     "16M 9S"      "15M 17S"     "21M 36S"    
 [351] "10M 44S"     "8M 13S"      "16M 26S"     "1M 30S"      "4M 44S"     
 [356] "16M 9S"      "7M 10S"      "7M 10S"      "4M 53S"      "3M 59S"     
 [361] "3M 50S"      "14M 10S"     "7M 28S"      "2M 28S"      "2M 41S"     
 [366] "6M 49S"      "5M 24S"      "7M 36S"      "8M 3S"       "25M 53S"    
 [371] "4M 21S"      "4M 56S"      "18M 48S"     "5M 34S"      "5M 22S"     
 [376] "4M 49S"      "4M 40S"      "21M 7S"      "4M 32S"      "11M 37S"    
 [381] "4M 48S"      "8M 56S"      "4M 41S"      "7M 11S"      "38M 7S"     
 [386] "37M 17S"     "31M 22S"     "5M 46S"      "7M 12S"      "31M 22S"    
 [391] "30M 34S"     "2H 5M 22S"   "30M 35S"     "1H 54M 57S"  "2M 53S"     
 [396] "9M 28S"      "3M 19S"      "22M 10S"     "6M 22S"      "7M 55S"     
 [401] "7M 21S"      "8M 51S"      "10M 11S"     "2M 18S"      "18M 22S"    
 [406] "8M 4S"       "10M 17S"     "26M 47S"     "4M 57S"      "28M 23S"    
 [411] "14M 14S"     "7M 13S"      "11M 19S"     "10M 27S"     "2M 41S"     
 [416] "2M 53S"      "11M 45S"     "3M 28S"      "18M 52S"     "13M 0S"     
 [421] "15M 43S"     "20M 12S"     "8M 4S"       "4M 28S"      "2M 46S"     
 [426] "4M 41S"      "5M 50S"      "29M 52S"     "24M 12S"     "36M 25S"    
 [431] "5M 45S"      "4M 17S"      "14M 2S"      "18M 34S"     "11M 50S"    
 [436] "6M 10S"      "12M 38S"     "13M 41S"     "7M 20S"      "21M 2S"     
 [441] "29M 24S"     "29M 24S"     "18M 51S"     "12M 35S"     "2M 25S"     
 [446] "6M 2S"       "6M 53S"      "29M 42S"     "16M 10S"     "3M 42S"     
 [451] "5M 23S"      "2H 36M 31S"  "8M 48S"      "12M 35S"     "7M 44S"     
 [456] "21M 55S"     "5M 40S"      "7M 55S"      "3M 53S"      "5M 4S"      
 [461] "6M 39S"      "1M 46S"      "6M 24S"      "9M 1S"       "17M 2S"     
 [466] "5M 30S"      "13M 20S"     "5M 13S"      "6M 43S"      "5M 24S"     
 [471] "18M 36S"     "15M 53S"     "5M 21S"      "6M 26S"      "5M 7S"      
 [476] "3M 32S"      "12M 1S"      "4M 50S"      "4M 47S"      "6M 9S"      
 [481] "6M 1S"       "19M 30S"     "7M 54S"      "7M 21S"      "1H 58M 49S" 
 [486] "11M 57S"     "4M 37S"      "6M 38S"      "13M 36S"     "2M 54S"     
 [491] "16M 34S"     "18M 42S"     "2M 41S"      "3M 6S"       "21M 39S"    
 [496] "8M 54S"      "2M 36S"      "24M 4S"      "23M 50S"     "16M 46S"    
 [501] "8M 54S"      "4M 40S"      "12M 44S"     "17M 28S"     "6M 6S"      
 [506] "17M 5S"      "2M 41S"      "7M 42S"      "5M 25S"      "17M 13S"    
 [511] "17M 18S"     "9M 31S"      "7M 29S"      "19M 16S"     "7M 36S"     
 [516] "5M 32S"      "5M 32S"      "21H 12M 30S" "3M 20S"      "9M 19S"     
 [521] "18H 30M 22S" "10M 6S"      "11M 26S"     "11M 56S"     "13M 49S"    
 [526] "8M 20S"      "47M 12S"     "17M 40S"     "4M 3S"       "2H 53M 17S" 
 [531] "8M 45S"      "7M 29S"      "15M 33S"     "54M 21S"     "8M 58S"     
 [536] "54M 31S"     "33M 10S"     "6M 6S"       "8M 35S"      "7M 42S"     
 [541] "15M 59S"     "7M 8S"       "22M 58S"     "3M 21S"      "5M 7S"      
 [546] "3M 5S"       "13M 27S"     "25M 39S"     "10M 51S"     "9M 0S"      
 [551] "10M 28S"     "9M 59S"      "6M 4S"       "6M 11S"      "6M 47S"     
 [556] "12M 23S"     "16M 27S"     "18M 29S"     "12M 40S"     "3M 26S"     
 [561] "20M 23S"     "8M 42S"      "4M 31S"      "6M 59S"      "10M 47S"    
 [566] "6M 13S"      "8M 19S"      "7M 21S"      "13M 2S"      "6M 38S"     
 [571] "56M 40S"     "5M 50S"      "3M 35S"      "7M 1S"       "6M 40S"     
 [576] "3M 38S"      "14M 31S"     "8M 31S"      "12M 6S"      "7M 50S"     
 [581] "16M 22S"     "21M 28S"     "21M 36S"     "8M 11S"      "16M 25S"    
 [586] "5M 53S"      "30M 16S"     "9M 39S"      "9M 50S"      "6M 1S"      
 [591] "7M 28S"      "6M 58S"      "6M 36S"      "10M 47S"     "20M 31S"    
 [596] "4M 18S"      "23M 43S"     "3M 43S"      "3M 43S"      "15M 44S"    
 [601] "15M 21S"     "11M 44S"     "5M 9S"       "28M 19S"     "26M 12S"    
 [606] "8M 32S"      "2H 12M 37S"  "27M 29S"     "5M 14S"      "9M 38S"     
 [611] "9M 38S"      "25M 2S"      "4M 24S"      "5M 43S"      "8M 40S"     
 [616] "13M 10S"     "13M 2S"      "9M 12S"      "13M 55S"     "3M 48S"     
 [621] "1M 18S"      "26M 6S"      "13M 12S"     "6M 28S"      "6M 5S"      
 [626] "11M 15S"     "6M 48S"      "10M 58S"     "5M 40S"      "9M 18S"     
 [631] "2M 24S"      "12M 1S"      "8M 5S"       "11M 58S"     "4H 35M 10S" 
 [636] "20M 12S"     "17M 46S"     "13M 14S"     "15M 49S"     "10M 32S"    
 [641] "9M 19S"      "5M 23S"      "4M 27S"      "12M 53S"     "11M 52S"    
 [646] "17M 59S"     "13M 18S"     "9M 22S"      "6M 12S"      "13M 48S"    
 [651] "5M 27S"      "16M 22S"     "22M 31S"     "6M 22S"      "4M 20S"     
 [656] "15M 43S"     "10M 2S"      "15M 0S"      "22M 13S"     "6M 46S"     
 [661] "10M 6S"      "14M 53S"     "8M 28S"      "8M 25S"      "5M 15S"     
 [666] "9M 7S"       "10M 1S"      "8M 55S"      "6M 2S"       "2M 37S"     
 [671] "2M 44S"      "13M 3S"      "14M 27S"     "23M 23S"     "7M 36S"     
 [676] "10M 46S"     "18M 44S"     "4M 45S"      "8M 19S"      "25M 20S"    
 [681] "5M 2S"       "5M 58S"      "11M 55S"     "4M 39S"      "10M 15S"    
 [686] "4M 23S"      "2M 22S"      "2M 44S"      "13M 53S"     "5M 55S"     
 [691] "8M 8S"       "9M 10S"      "18M 1S"      "19M 43S"     "18M 39S"    
 [696] "20M 24S"     "3M 37S"      "28M 0S"      "7M 12S"      "6M 13S"     
 [701] "7M 11S"      "5M 38S"      "21M 44S"     "9M 16S"      "3M 47S"     
 [706] "2M 47S"      "9M 53S"      "5M 54S"      "4M 25S"      "19M 40S"    
 [711] "9M 24S"      "4M 33S"      "1M 58S"      "19M 16S"     "3M 27S"     
 [716] "22M 20S"     "8M 35S"      "6M 20S"      "25M 3S"      "5M 31S"     
 [721] "13M 56S"     "27M 27S"     "27M 28S"     "10M 13S"     "36M 53S"    
 [726] "12M 17S"     "43M 43S"     "43M 38S"     "6M 28S"      "42M 53S"    
 [731] "17M 37S"     "17M 10S"     "6M 40S"      "9M 11S"      "5M 9S"      
 [736] "1M 54S"      "24M 10S"     "2M 28S"      "4M 10S"      "23M 11S"    
 [741] "14M 20S"     "18M 23S"     "5M 19S"      "5M 38S"      "15M 5S"     
 [746] "18M 36S"     "2M 15S"      "8M 12S"      "3M 39S"      "16M 4S"     
 [751] "6M 47S"      "7M 22S"      "4M 42S"      "1M 10S"      "12M 5S"     
 [756] "11M 25S"     "39M 35S"     "11M 56S"     "27M 59S"     "13M 53S"    
 [761] "13M 27S"     "5M 1S"       "17M 37S"     "18M 20S"     "5M 6S"      
 [766] "19M 48S"     "4M 26S"      "10M 7S"      "9M 11S"      "34M 53S"    
 [771] "34M 30S"     "4M 14S"      "41M 40S"     "1M 53S"      "8M 51S"     
 [776] "7M 22S"      "5M 15S"      "11M 49S"     "18M 22S"     "4M 53S"     
 [781] "7M 52S"      "4M 52S"      "9M 49S"      "20M 39S"     "5M 11S"     
 [786] "11M 39S"     "25M 30S"     "25M 20S"     "25M 28S"     "22M 37S"    
 [791] "25M 4S"      "9M 6S"       "9M 25S"      "14M 45S"     "4M 51S"     
 [796] "5M 44S"      "6M 10S"      "5M 21S"      "22M 10S"     "1H 47M 23S" 
 [801] "6M 20S"      "26M 53S"     "15M 38S"     "29M 22S"     "7M 13S"     
 [806] "13M 54S"     "9M 49S"      "6M 13S"      "13M 37S"     "3M 21S"     
 [811] "4M 12S"      "3M 9S"       "6M 47S"      "7M 35S"      "7M 41S"     
 [816] "28M 23S"     "11M 41S"     "16M 12S"     "8M 51S"      "16M 35S"    
 [821] "29M 47S"     "31M 20S"     "10M 42S"     "31M 14S"     "12M 3S"     
 [826] "39M 44S"     "9M 3S"       "39M 30S"     "21M 26S"     "11M 3S"     
 [ reached getOption("max.print") -- omitted 364069 entries ]
> ```

But how do I include that in this code?

library(tidyverse)
library(tidymodels)
library(hms)
lubridate::hms(dataset2$ride_length)
dataset2 <- read.csv("Bike_Trips_2019.csv")
dataset2$user_type <- factor(dataset2$user_type, levels = c("Customer", "Subscriber"), labels = c("no","yes"))
dataset2$trip_id <- as.character(dataset2$trip_id)
dataset2$start_time <- as.POSIXct(dataset2$start_time)
dataset2$end_time <- as.POSIXct(dataset2$end_time)
dataset2$tripduration <- parse_number(dataset2$tripduration)
dataset2$ride_length <- lubridate::hms(ride_length) |>
hms::hms()
set.seed(421)
split <- initial_split(dataset3, prop = 0.8, strata = user_type)
train <-split %>% training()
test <- split %>% testing()
print(split)
print(test)
print(train)

Output:

Error: object 'ride_length' not found

This topic was automatically closed 21 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.