how do you convert a factor that has 3 digits miliseconds to datetime in R?

前端 未结 3 1276
攒了一身酷
攒了一身酷 2021-01-27 09:40

I time a t object like this:

t<-c(\"2016-10-19 00:00:00.000\")

I need to convert to POSIXct as this:

as.POSIXct(t, format=\"         


        
相关标签:
3条回答
  • 2021-01-27 10:07

    You could use lubridate too :

    library(lubridate)
    t<-c("2016-10-19 00:00:00.000")
    ymd_hms(t)
    #> [1] "2016-10-19 UTC"
    
    0 讨论(0)
  • 2021-01-27 10:13

    The new and easy-to-use package anytime is an alternative:

    library(anytime) 
    anydate(t$Datetime)
    
    0 讨论(0)
  • 2021-01-27 10:15

    You didn't lose them, that's just the default for when the hours, minutes and seconds are zero. You can specify a format string to force these to be printed:

    > ct <- as.POSIXct(t, format="%Y-%m-%d %H:%M:%OS")
    > format(ct, "%Y-%m-%d %H:%M:%S")
    [1] "2016-10-19 00:00:00"
    
    0 讨论(0)
提交回复
热议问题