I have a variable which is the concatenation of month and year, in a numeric format. The month is in format 1-12, not 01-12.
My variable looks like:
mmyyyy
12014
22014
102014
52015
112015
I am looking for a regexp to match the month or the year only:
for year, I did something like:
year <- ifelse(grepl("2014", mmyyyy), 2014, ifelse(grepl("2015", mmyyyy), 2015, 2016))
But for the month, I am struggling. My first thought is to replace 2014, 2015, etc. by blank then to convert the result in numeric.
month <- as.numeric(gsub("[[^2014]]", "", mmyyyy))
but here, I can't find a suitable regexp expression.
In the end, I would like a variable/ vector with the numeric year(yyyy) and a variable/vector with the numeric month.