Convert roman numerals to integers
roman2int(roman)A integer vector with the same length as roman. Character
strings which are not valid roman numerals will be converted to NA.
This function will convert roman numerals to integers without the upper bound imposed by R (3899), ignoring case.
roman2int(c("I", "V", "X", "C", "L", "D", "M"))
#> I V X C L D M
#> 1 5 10 100 50 500 1000
# works regardless of case
roman2int("MMXVI")
#> MMXVI
#> 2016
roman2int("mmxvi")
#> MMXVI
#> 2016
# works beyond R's limit of 3899
val.3899 <- "MMMDCCCXCIX"
val.3900 <- "MMMCM"
val.4000 <- "MMMM"
as.numeric(as.roman(val.3899))
#> [1] 3899
as.numeric(as.roman(val.3900))
#> [1] 3900
as.numeric(as.roman(val.4000))
#> [1] 4000
roman2int(val.3899)
#> MMMDCCCXCIX
#> 3899
roman2int(val.3900)
#> MMMCM
#> 3900
roman2int(val.4000)
#> MMMM
#> 4000