I have this dataset, i paste only few data

"73C23" "62R31" "62M26" "58C44" "53R02" NA "78R58" "76C63"

I'm trying to write a function that does the following operations on strings: the first two numerical values must be extracted and compared with the parameter 18, if > 18 must be added to 1900, if <= must be added to 2000 and make a separate Year column. the central letter must be compared with this legend: mesi_legend head(mesi_legend) January February March April May June "A" "B" "C" "D" "E" "H" And it is written on another column

While for the last final numbers must be extracted normally if male, subtracted 40 if female (as a discrimine I can use > 31, subtract 40 but I have margin of error i think.

i start from this:

"GFNNTN78R58G812M"

first step> "78R58"

Output_of_my_function(78R58) > Year 1978 Month October Day 18

Can someone help me?