Convert roman numerals to integers

RomanToInt(x)

Arguments

x

character vector containing roman numerals

Details

This functon will convert roman numerals to integers without the upper bound imposed by R (3899), ignoring case.

Value

A integer vector with the same length as roman. Character strings which are not valid roman numerals will be converted to NA.

Author

Gregory R. Warnes <greg@warnes.net>

See also

Examples

RomanToInt( 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
RomanToInt( 'MMXVI' )
#> MMXVI 
#>  2016 
RomanToInt( '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] NA

RomanToInt(val.3899)
#> MMMDCCCXCIX 
#>        3899 
RomanToInt(val.3900)
#> MMMCM 
#>  3900 
RomanToInt(val.4000)
#> MMMM 
#> 4000