My sample dataset
data = c("2-2021", "8-2020", "11-2020", "11-2020", "7-2021", "12-2020",
"2-2021", "5-2021", "11-2020", "11-2020")
I require to add a leading zero to the month where applies.
Running this will throw all NA's
as.Date(data,format="%m-%Y")
So the desired output becomes
c("02-2021", "08-2020", "11-2020", "11-2020", "07-2021", "12-2020",
"02-2021", "05-2021", "11-2020", "11-2020")