【问题标题】:how to save the date and time value in the variable as posixct [closed]如何将变量中的日期和时间值保存为posixct [关闭]
【发布时间】:2022-01-25 21:14:27
【问题描述】:

我正在尝试手动输入两个不同的时间,我想保存在变量中,并希望稍后在图中使用它。但我目前在变量 E 中得到 NA。有人可以查看并描述问题所在吗?

lab_time<-c("22.11.2021 22:45, 22.11.2021 23:25")

E<-as.POSIXct(lab_time,format='%d.%M.%y %h:%m')

【问题讨论】:

  • 试试lab_time &lt;- c("22.11.2021 22:45", "22.11.2021 23:25")
  • 你又打错了...
  • 是的,我纠正了一个拼写错误并且它有效。非常感谢您的回答。

标签: r time-series


【解决方案1】:

您的 lab_time 变量是一个字符串,但它们必须是单独的字符串。

lab_time <- c("22.11.2021 22:45", "22.11.2021 23:25")

此外,格式必须是“H”代表小时,“M”代表分钟,“m”代表月份,“Y”代表 4 位数年份(世纪)。

汇总:

as.POSIXct(lab_time, format='%d.%m.%Y %H:%M')
[1] "2021-11-22 22:45:00 CET" "2021-11-22 23:25:00 CET"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多