Hmisc: label a data.frame column with hms format

48 Views Asked by At

I'm trying to label a data.frame with one of the columns of the format 'hms', as follows:

library(Hmisc)

data <- data.frame(time = c(hms::hms(20, 20, 20), hms::hms(30, 20, 10)),
                   date = c(as.Date("2001/01/01"), as.Date("2001/01/01")))

label(data) <- list(time = "Time", date = "Date")

However, I get the following error when trying to view the data.frame in RStudio

Error in `as.character()`:
! Can't convert `x` <labelled> to <character>.
Run `rlang::last_trace()` to see where the error occurred.

The issue is with the time variable

1

There are 1 best solutions below

1
Near Lin On

Try:

attributes(data$time)$label <- "Time"