Hmisc:用 hms 格式标记 data.frame 列

问题描述 投票:0回答:1

我正在尝试使用格式为“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
变量

r lubridate hmisc
1个回答
0
投票

尝试:

attributes(data$time)$label <- "Time"
© www.soinside.com 2019 - 2024. All rights reserved.