# R vs MATLAB (Round 3)

At least for me, R by faR. MATLAB has its own way of doing things, which to be honest can probably be defended from many angles. Here are few examples for not so subtle differences between R and MATLAB:

• Writing default arguments in MATLAB is exhausting compared to the amazingly trivial R-way of doing it:
• It is my preference not to clutter the directory with too many files (it is a mess as it is), R lets you write all the functions in one script, say ‘Proj_Functions.R’, then you can source that script and voila*. MATLAB forces each function to have its own file. One can claim it is better organized that way, I prefer to be more compact with my directories.
• MATLAB, in a way, forces you to properly document your function. I often forget the arguments of a function I wrote, in R: type ‘function_name’ of the function to print it to screen to remember what you did, in MATLAB: help ‘function_name’. If you wrote the help section, there you have it, if not, go open the file (though you can relatively quickly do that with: edit ‘function_name’).
• R lets you keep on writing your code, while MATLAB forces you to organize it for better readability, see what I mean:
• Again, I see the rational behind these delays, shortcuts can cause issues down the road, but perhaps not bad where appropriate, it is a matter of preference.

• Another thing which I find convenient in R and awkward in MATLAB is extracting singular result from a multiple outputs function. For example the function ?dm.test in ‘forecast’ package returns 6 different outputs, including the statistic and p.value. If you only need the p.value, you can use the “$” operator to extract it. In contrast, you need to let MATLAB know that you do not need: • In MATLAB, you can forget about mixing different kinds of classes in the same matrix, which is a breeze in R, we just use data.frame: I don’t think this is possible in MATLAB, only workarounds using probably ‘cell’ class. • I like to work slow and to run each line separately, R lets you do that without selecting the line each time, it is enough that the cursor is there. • Printing to screen is well thought of in R, less so in MATLAB: Got to enjoy the little things eh? As a final word, I predict that in the future R will simply dominate all other paid competitive software. Think about it, how the hell can these firms compete with the open source community? Thinking about labor productivity, those commercial firms need to be more efficient than the thousands (it will be tens of thousands) programmers that are so passionate to give back, they are working for free. Moving forward, pushing the boundaries, for free. Don’t let it go over your head, see how the workflow is smoothed slowly but surely. From the clunky carriage it used to be to the glistening porsche it is going to be. Work in progress include (but not limited to) R-studio (Hadley), Knitr (Yihui Xie), Googleivs (Markus). Recently I used some tools that were developed for laymen like myself to be able to make my code public: devtools. The R-team, talented experienced professionals lubricating those tools to allow the safe service of thousands of packages written to facilitate applications with whatever state-of-the-art statistic and econometric techniques you can think of. Books are slowly becoming free as well: a good example is Forecasting: principles and practice which demonstrates the potential of the platform (the book is excellent as expected). Here are some other books posted by Francis Diabold. Monetary compensation is secondary at best. There are many areas where ‘old-school’ business plans have to be reconsidered. The future is here, it is just not widely distributed yet (William Gibson). There are (way) too many altruistic selfless professionals giving their time for anyone to stop it. *You can source few scripts: sapply(FilesToLoad,source,.GlobalEnv). ### 9 comments on “R vs MATLAB (Round 3)” 1. John Hall says: Yeah, there definitely are some kinks to Matlab (I’d quibble with a few, you can output a structure that has similar functionality as Rs$ and I like the way Matlab labels what columns are stuff when you print ’em). However, it is almost always faster than R at everything. Also, in spite of some of its convenience, there are all sorts of funky kinks to R as well. Python is way better organized. Unfortunately, it can be slower than R at some things unless you spend the effort to speed ’em up.

2. gigi says:

What about Python? It has an even stronger community and it’s advancing rapidly in data science capabilities.

3. Owe says:

Pardon, but where is part 2?

4. Justinas Brazys says:

Nice points. At least what I find nice in Matlab is debugging and fast plotting

5. Tanmay says:

Try python, you won’t need Matlab/R, and you won’t be dissatisfied.
I was a Matlab user, went on to R for a while and now work on Python.

6. Ruben says:

Hi Eran,
nice post. By the way, have you considered using Mathematica?
I’m a big fan of R as well but sometimes I don’t trust the results, specially if I’m using a CRAN package. Mathematica is also more flexible and cheaper than Matlab.
The function definition would simply be:
myFunction[x_,y_:2]:=x+y
You could also get the range directly by:
Range[10][[1;;4]]
and so on.