Learn R Programming

DescTools (version 0.99.53)

RomanToInt: Convert Roman Numerals to Integers

Description

Convert roman numerals to integers

Usage

RomanToInt(x)

Value

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

Arguments

x

character vector containing roman numerals

Author

Gregory R. Warnes <greg@warnes.net>

Details

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

See Also

Examples

Run this code
RomanToInt( c('I', 'V', 'X', 'C', 'L', 'D', 'M' )  )

# works regardless of case
RomanToInt( 'MMXVI' )
RomanToInt( 'mmxvi' )

# works beyond R's limit of 3899
val.3899 <- 'MMMDCCCXCIX'
val.3900 <- 'MMMCM'
val.4000 <- 'MMMM'
as.numeric(as.roman( val.3899 ))
as.numeric(as.roman( val.3900 ))
as.numeric(as.roman( val.4000 ))

RomanToInt(val.3899)
RomanToInt(val.3900)
RomanToInt(val.4000)

Run the code above in your browser using DataLab