## MATLAB and R ‘Rosetta Stone’

I was recently given the task of converting a small piece of code written in R, the free open-source programming language heavily used by statisticians, into MATLAB which was an interesting exercise since I had never coded a single line of R in my life! Fortunately for me, the code was rather simple and I didn’t have too much trouble with it but other people may not be so lucky since both MATLAB and R can be rather complicated to say the least. Wouldn’t it be nice if there was a sort of Rosetta Stone that helped you to translate between the two systems?

Happily, it turns out that there is in the form of The MATLAB / R Reference by David Hiebeler which gives both the R and MATLAB commands for hundreds of common (and some not so common) operations.

While flicking through the 47 page document I noted that there are a few MATLAB commands for which David hasn’t found an R equivalent (possibly because there simply isn’t one of course). For example, at number 161 of David’s document he describes the MATLAB command

**yy=spline(x,y,xx) **

which he describes as

*‘Fit cubic spline with “not-a-knot” conditions (the first two piecewise cubics coincide,as do the last two), to points (xi , yi ) whose coordinates are in vectors x and y; evaluate at points whose x coordinates are in vector xx, storing corresponding y’s in yy.’*

At the moment David doesn’t know of an R equivalent so if you are a R master then maybe you could help out with this extremely useful document?

Mike,

do you know how much NAG cost for student?

Hi HP

I’m not sure I’m afraid as my university has a full site license for them and we can give it to all of our students for free (well, free to them at least).

However, I am in regular contact with the people at NAG and so, if you would like me to, then I could put you in contact with someone who could give you a price.

Is the email address you supplied to your comment your actual email address? If so then we can discuss this by email.

Cheers,

Mike

Take a look at Rosetta Code (http://rosettacode.org). This has solutions to many common programming problems in many languages. It’s in wiki format, so you can add your own. R is reasonably well represented, but MATLAB solutions are patchy at the moment.

Thanks Richie that looks quite useful,

Mike