You can't have a date that is a month and year. A date is a day of that month. So there are a few ways to tackle this depending what your end goal is and the quality of your data.
If you consider February 2021 to be 2021-02-01 and you currently have myDate = "202102"
Add the 01 on the end and then do the date manipulation:
myDate <- "202102"
myDate <- paste0( myDate, "01")
myRealDate <- as.Date ( myDate )
myYear <- format(myRealDate, "%Y")
myMonth <- format (myRealDate, "%m")
Or you could use string manipulation to get the first four and last 2 characters
myDate <- "202102"
myYear <- substr( myDate, 1, 4)
myMonth <- substr( myDate, 5, 6)
What you plan to do with them will depend what the right solution is.
Output will be character, but can be made numeric.
First example can be made slicker by nesting