r - 日期时间值在 DT :datatable() 中显示损坏

标签 r datetime dt

我有下面的数据框,我想将其显示为 DT::datatable()

library(DT)
library(lubridate)
eventex <- structure(list(registration_type = c("Start", "Stopp"),
                         timestamp = c("25.11.2022 13:19:42", 
                                       "31.10.2022 14:19:13")),
                         row.names = c(NA, -2L), 
                         class = c("tbl_df", "tbl", "data.frame"))

eventex$timestamp<-as.POSIXct( paste0(eventex$timestamp),
                               format="%d.%m.%Y %H:%M:%S")

datatable(eventex)

为什么会这样显示? enter image description here

最佳答案

人们对“正常”的定义可能会有所不同,尤其是在假设美国常用的模棱两可(且不合理)的惯例时。有一个 formatDate 函数可以应用于您的日期时间列。 (这些选项在 R 包中没有详细记录):

DT:::DateMethods
[1] "toDateString"       "toISOString"        "toLocaleDateString" "toLocaleString"     "toLocaleTimeString"
[6] "toString"           "toTimeString"       "toUTCString"   

datatable(eventex) %>% formatDate(~timestamp, "toLocaleString" )

enter image description here

更多信息和工作示例可以在这里找到:https://rstudio.github.io/DT/functions.html

关于r - 日期时间值在 DT :datatable() 中显示损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74805556/

相关文章:

r - 描述性表格 - 如何创建包含数值变量和分类变量的表格

r - 如何解决extrafont中的错误状态5?

r - 使用 glm.fit 、 bigglm、 speedglm、 glmnet、 LiblineaR 对逻辑回归进行基准测试

shiny - DT::datatable 的背景颜色 Shiny

javascript - 使用回调选项选择新页面后,R DT 数据表不保留行索引/计数器列

r - 在 R 中剥离向量中的非 A-Z 字符

python - 合并年和周列以在 python 中创建日期时间和排序

mysql - 是否可以优化具有日期时间字段差异的mysql查询?

javascript - 使用 moment.js 在 HTML5 <time> 元素中插入日期

r - 将标签添加到数据表中的迷你图