Incorrect Conversion of Date as a Factor to a Date

前端 未结 2 2044
春和景丽
春和景丽 2021-01-06 17:53

I am having trouble calculating a date that is imported in from a .csv file. What I want to do is take that date in the factor DateClosed and generate a date in a date fie

2条回答
  •  庸人自扰
    2021-01-06 18:43

    Manipulating dates becomes really easy using lubridate package.

    mdy(factor(c("7/30/2007","12/12/2007", "5/8/2009")))
    
    "2007-07-30 UTC" "2007-12-12 UTC" "2009-05-08 UTC"
    

    Or using parse_date_time with the same package:

    parse_date_time(factor(c("7/30/2007","12/12/2007", "5/8/2009")),c('mdY'))
    [1] "2007-07-30 UTC" "2007-12-12 UTC" "2009-05-08 UTC"
    

提交回复
热议问题