我有一个时间戳数据具有以下结构,其中日期和时间以下列方式显示:
timestamp
January 22,2013 20:56
January 22,2013 08:53
January 22,2013 20:59
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能把它变成R中的时间对象?我打算编写一个perl脚本将数据转换为YEAR-MONTH-TIME HH:MM:SS格式,并使用POSIXct将其导入日期时间对象,但我想知道是否有一个快捷方式可以执行此操作R.
您可以使用 strptime
strptime('January 22,2013 20:56','%b %d,%Y %H:%M')
[1] "2013-01-22 20:56:00"
Run Code Online (Sandbox Code Playgroud)
PS:这取决于你当地人:
Sys.setlocale('LC_TIME','FRENCH')
[1] "French_France.1252"
strptime('January 22,2013 20:56','%b %d,%Y %H:%M')
[1] NA
Sys.setlocale('LC_TIME','ENGLISH')
[1] "English_United States.1252"
strptime('January 22,2013 20:56','%b %d,%Y %H:%M')
[1] "2013-01-22 20:56:00"
Run Code Online (Sandbox Code Playgroud)