楼主: yfen339
7511 1

[问答] R语言 关于函数as.POSIXct的问题 [推广有奖]

  • 2关注
  • 0粉丝

大专生

75%

还不是VIP/贵宾

-

威望
0
论坛币
998 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1500 点
帖子
64
精华
0
在线时间
60 小时
注册时间
2009-6-5
最后登录
2018-1-28

楼主
yfen339 发表于 2016-8-4 15:23:26 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
处理日期数据的时候,使用了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")
}
二维码

扫码加我 拉你入群

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

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

关键词:OSI R语言 POS Six function function return

沙发
yfen339 发表于 2016-8-4 15:24:12
错误内容如下:

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

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-22 15:20