在R中转换时间格式

在R中转换时间格式,r,datetime,time,format,R,Datetime,Time,Format,我对时间数据的观察之一是“Wed Oct 31 13:42:46 2007”。 我想将格式转换为“2007-10-3113:42:46”(删除Wed)。 我如何转换它 正如@thelatemail所说 x <- "Wed Oct 31 13:42:46 2007" x <- as.POSIXct(x, format = "%a %b %d %T %Y", tz = "GMT") # %a day of week, %b month of year, %d day of month

我对时间数据的观察之一是“Wed Oct 31 13:42:46 2007”。 我想将格式转换为“2007-10-3113:42:46”(删除Wed)。 我如何转换它

正如@thelatemail所说

x <- "Wed Oct 31 13:42:46 2007"
x <- as.POSIXct(x, format = "%a %b %d %T %Y", tz =  "GMT")
# %a day of week, %b month of year, %d day of month as decimal, %T H:M:S, %Y year with century
x
[1] "2007-10-31 13:42:46 GMT"

x有关
format
-ting Date和POSIX datetime对象的所有选项,请参见
?strtime
。尝试:
as.character(as.POSIXct(“Wed Oct 31 13:42:46 2007”,format=“%a%b%d%H:%M:%S%Y”)