全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
7447 1
2016-08-04
处理日期数据的时候,使用了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")
}
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-8-4 15:24:12
错误内容如下:

Error in as.POSIXlt.character(as.character(x), ...) :
  character string is not in a standard unambiguous format
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群