Converting character to timestamp in dataframe

后端 未结 2 1628
予麋鹿
予麋鹿 2021-01-22 07:37

I have a timestamp in a dataframe that is recognized as a character class. For some reason, I am not able to convert it to a poxis timestamp.

Here is a sample of the da

2条回答
  •  失恋的感觉
    2021-01-22 08:06

    Z means it's UTC time. So one option is just to strip out the letter and convert to POSIXCT with tz="UTC" . As the dataframe is not easily reproducible, I'm just using the vector of two dates:

    x<- as.POSIXct( gsub(pattern = "[A-Z]",replacement = " ",
                     x = c( "2016-11-01T00:45:00.000Z","2016-11-01T00:39:00.000Z") ) ,
                     tz="UTC" ) 
    x
    class(x)
    

提交回复
热议问题