I am working on a dataset. Variable date has the character type data in this format"13-Dec-2012". I need to convert this character into date format. I tried some ways but couldn't figure it out. Any help is appreciated. Thanks
Asked
Active
Viewed 419 times
1 Answers
1
We can use the lubridate
package. dmy
means day-month-year
.
library(lubridate)
dmy("13-Dec-2012")
# [1] "2012-12-13"
Or use the base R. See this link to learn more about the format of date specification (https://www.statmethods.net/input/dates.html).
as.Date("13-Dec-2012", format = "%d-%b-%Y")
# [1] "2012-12-13"
Or use the anydate
function from the anytime
package.
library(anytime)
anydate("13-Dec-2012")
# [1] "2012-12-13"

www
- 38,575
- 12
- 48
- 84