简体   繁体   English

as.Date 没有将字符日期转换为 R 中的日期

[英]as.Date not converting character date to date in R

I am trying to convert a character date to date but result is somehow a double.我正在尝试将字符日期转换为日期,但结果不知何故是双倍的。

> x
[1] "2017-10-31"
> as.Date(x)
[1] "2017-10-31"
> as.Date(x) %>% typeof
[1] "double"

> as.Date(x,format="%Y-%m-%d") %>% typeof
[1] "double"

According to ?typeof根据?typeof

typeof determines the (R internal) type or storage mode of any object typeof 确定任何 object 的(R 内部)类型或存储模式

Instead of typeof , check the class而不是typeof ,检查class

library(magrittr)
as.Date(x) %>%
    class
# [1] "Date"

Also, can be checked with inherits此外,可以通过inherits检查

as.Date(x) %>%
   inherits('Date')
#[1] TRUE

data数据

x <-  "2017-10-31"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM