Search code examples
rdifftime

Converting Time datatype to character string in R language


When selecting the 'Time' column from the dataframe, I get the time in "%H:%M:%S" format

> tail(sf_arrest[,c("Time")],1)
# A tibble: 1 × 1
      Time
    <time>
1 06:44:00

I would like to convert this to character format like "06:44:00". For some reason, "as.character" gives the difftime output than the expected one

> as.character(tail(sf_arrest[,c("Time")],1))
[1] "24240"

How to perform direct character conversion?


Solution

  • As it is a tibble, we can extract the column with [[ instead of [ and convert to character

    as.character(sf_arrest[["Time"]])