Hi I am completely new to R-programming, for a project need to find the max of a time type column from an imported csv file.
preview of the column: of the time type format %H:%M:%S
table name : X202302_divvy_tripdata
Code used to find the MAX:
library(chron)
ride_length_chron <- chron(times. = combined_table$ride_length)
max_ride_length <- max(ride_length_chron)
max_ride_length_format <- format(max_ride_length, format. = "%H:%M:%S")
max_ride_length_format
In this code I am getting an error as the output is showing as : "NA"
>Solution :
I’ve never used the chron package, but this seems to work if you have a character variable after you’ve imported your data:
library(chron)
# assertion to check data type since this is not clear in the question
stopifnot(class(combined_table$ride_length) == "character")
ride_times <- times(combined_table$ride_length)
max(ride_times)
If you have missing values in the ride_length column, you can either change the raw data, or exclude the missing values when calculating the maximum:
max(ride_times, na.rm = TRUE)
The times function within the chron package returns at times class which is non-standard. After calculating your maximum time, you could coerce the value to a character if easier to work with.