处理日期数据的时候,使用了as.POSIXct函数,但是现在发现一个问题,这个函数貌似不能处理类似于
"%Y-%m-%d %H:%M:%S"的日期格式。请教该如何处理?非常感谢!
使用Debug模式得到的 as.POSIXct 函数如下:
function (x, tz = "", format, ...)
{
x <- unclass(x)
if (!missing(format)) {
res <- strptime(x, format, tz = tz)
if (nzchar(tz))
attr(res, "tzone") <- tz
return(res)
}
xx <- x[!is.na(x)]
if (!length(xx)) {
res <- strptime(x, "%Y/%m/%d")
if (nzchar(tz))
attr(res, "tzone") <- tz
return(res)
}
else if (all(!is.na(strptime(xx, f <- "%Y-%m-%d %H:%M:%OS",
tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d %H:%M:%OS",
tz = tz))) || all(!is.na(strptime(xx, f <- "%Y-%m-%d %H:%M",
tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d %H:%M",
tz = tz))) || all(!is.na(strptime(xx, f <- "%Y-%m-%d",
tz = tz))) || all(!is.na(strptime(xx, f <- "%Y/%m/%d",
tz = tz)))) {
res <- strptime(x, f, tz = tz)
if (nzchar(tz))
attr(res, "tzone") <- tz
return(res)
}
stop("character string is not in a standard unambiguous format")
}