문제

I have input data with date and time stamps as "140128142257" which is the equivalent of "14/01/28 14:22:57" or "%Y/%m/%d %H:%M:%S".

I cannot get R to read this in so I can convert it to a usable date and timestamp. Any helpful advice would be appreciated.

Here is what I have tried:

datetime <- as.POSIXct(strptime(date[,2],format="%Y%m%d%H%M%S")

However this just gives NA * length of array.

도움이 되었습니까?

해결책

The uppercase %Y is used for four-digit years. You have to use %y for two-digit years.

strptime("140128142257", format = "%y%m%d%H%M%S")
# [1] "2014-01-28 14:22:57"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top