Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

Although virtually obsolete, Roman Numerals are subtly embedded into our culture. From the Super Bowl and Olympics to royal titles, Roman Numerals refuse to fully be extinguished from our every day lives. And that’s not without reason. All numbers are beautiful and Roman Numerals are no exception, even if they are written a little differently from their Arabic counterparts.

In this post, we’ll examine some fascinating properties of Roman Numerals – namely the lengths of Roman Numerals in succession.

First, we define a simple Arabic –> Roman Numeral converter. Start by creating two vectors, one for the 13 Roman symbols and another for the Arabic counterparts. Next, a simple for/while combination iterates through the arrays and chooses the appropriate Roman symbols while iteratively decreasing the input variable.

12345678910111213

arabic <-c(1000,900,500,400,100,90,50,40,10,9,5,4,1)roman <-c("M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I")toRoman <-function(n){ ans <-c()for(i in1:length(arabic)){while(n >= arabic[i]){ ans <-c(ans, roman[i]) n <- n - arabic[i]}} ans
}

Next we want to find the lengths of each of these representations:

qplot(1:3999, lens, geom ="line")+ xlab("Numbers")+ ylab("Length of Roman Numeral")+ ggtitle("1 - 3999 Length of Roman Numerals")+ geom_smooth(method ="lm")

What a fascinating relationship! The lengths seem to take a sinusoidal shape with positive drift. We can see that although the average length keeps rising, the plot goes through very regular cycles of rising and falling.

Related

To leave a comment for the author, please follow the link and comment on their blog: Frank Portman.