How to convert a string factor into Date?

前端 未结 5 1017
情话喂你
情话喂你 2021-01-24 17:52

I\'m working with the London crime dataset which contains dates in an integer format. I melted them and now they have become factors.

For example, \"

5条回答
  •  悲&欢浪女
    2021-01-24 18:05

    You can use parse_datetime from the readr package:
    testdate <- factor("X200801")
    parse_datetime(as.character(testdate), format = 'X%Y%M')

    I wouldn't recommend using MM/DD/YYY in R. Keeping things in the ISO 8601 format is preferable.

提交回复
热议问题