Hi, I'm new to R and I'm having trouble with dates. I've uploaded a csv file, which contains a column of dates in the format month-year (e.g. Jan-16). This is recognised by R as a factor.
I'd like to change this format to mm/yyyy (e.g. 01/2016) and have R recognise this as a date variable. Here's what I've tried:
library("lubridate") Data$Month <- parse_date_time(Data$Month, "%b-%y") # This converts the dates to yyyy-mm-dd, with all day values defaulting to 01 as I do not have values for them.
To get R to recognise this as a date variable I did the following:
I do not have values for the days and do not want these to appear, so to remove them and display the dates how I want, mm/yyyy, I did the following:
Data$Month<-format(as.Date(Data$Month, "%Y-%m-%d"), "%m/%Y")
This successfully formats my dates as mm/yyyy, but changes the variable type to character instead of date. Is there a way to set the variable type back to date, whilst keeping this format?