Changing the character of a factor variable into numeric but preserving the original number used in the coding

I am having a bit of trouble getting the original codes of the factors of the dataframe imported from STATA. Now when I import the file, the character of the factor is shown . But, I want to get the original codes of the factors which were used to name the factors. Simply, I want to preserve the original code of the factors. However, when I use the as.numeric it gives new numbers than the originally coded numbers.

Hi @Sanjeev_Nhemhafuki , could you post just a simple reproducible example - it would be easier for the rest of us to provide you with code which will resolves your issue.

1 Like