How to convert date in format mm/yy from character to date class?

Danny_0101

Just a brief (and hopefully simple!) question;

I have a column of dates such as 08/14 and 08/15. However the column class is character, and I was wondering if it is possible (and if so how) to convert this into a date class? I've tried lots of different ways and it either does nothing, or returns N/A values for the whole column. Hopefully there should be a simple line of code to fix this that I haven't come across yet?

Any help much appreciated!!

akrun

One option is to create a day by pasteing and then use as.Date because date also needs day info

as.Date(paste0(c("08/14", "08/15"), "/01"), format = "%m/%y/%d")
#[1] "2014-08-01" "2015-08-01"

Or make use of as.yearmon from zoo

library(zoo)
as.Date(as.yearmon(c("08/14", "08/15"), "%m/%y"))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive