我正在尝试使用格式为“hms”的列之一来标记 data.frame,如下所示:
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")
但是,在尝试在 RStudio 中查看 data.frame 时出现以下错误
Error in `as.character()`:
! Can't convert `x` <labelled> to <character>.
Run `rlang::last_trace()` to see where the error occurred.
问题出在
time
变量
尝试:
attributes(data$time)$label <- "Time"