Reputation: 1770
Related: Convert roman numerals to numbers in R
In the above question, an answer states that there is a function utils:::.roman2numeric()
to convert roman to numeric. I also found out that there is a similar function to convert numeric to roman: utils:::.numeric2roman()
. Unfortunately it does not work for some numbers, why?
E.g. 3978
, 3985
produces NA
This is similar to how as.roman()
doesn't work for some roman numbers converting to numerics. E.g. MMMCMXI
gives NA
instead of 3911
.
Is there another function that works for numeric to roman 100% of the time? (Best if it's builtin)
Bonus: another function that works, other than utils:::.roman2numeric()
, for roman to numeric. (as.roman()
does not work as explained earlier).
Upvotes: 1
Views: 300
Reputation: 33792
From the help page ?utils::as.roman
:
Only numbers between 1 and 3899 have a unique representation as roman numbers, and hence others result in as.roman(NA).
Here is a function that claims to convert larger numeric values to Roman.
For the other direction you could try gtools::roman2int.
Upvotes: 5