Skip to content
BENIBIX Learn

R, Julia and MATLAB

Level 5 · Data and functional languages

Three languages built for data, statistics and maths. How they work on a whole column of numbers at once, and why they count from 1.

Course contentsLesson 10 of 12

Level 3 · General-purpose and systems languages

  1. Python, Java and C#
  2. C, C++, Rust and Go

Level 4 · Languages for phones

  1. Swift, Kotlin and Dart

Level 5 · Data and functional languages

  1. R, Julia and MATLAB
  2. Haskell, Scala and Elixir

Level 6 · Scripting languages

  1. Shell Scripts, Perl and Lua

After this lesson you can

  • Say what R, Julia and MATLAB are each used for
  • Explain working on a whole list at once
  • Remember that these languages count from 1

11 mincovers 3 glossary entries

Worth reading first: Python, Java and C#

Which languages are built for numbers and data

Some languages are built for maths, statistics and science. R is free and made for statistics and charts. MATLAB is a paid product for engineers working with tables of numbers. Julia is free and aims to be as easy as Python and nearly as fast as C. All three start counting their lists at 1, not 0.

Their big idea is working on a whole list of numbers at once. In these languages, prices * 2 doubles every price in the list in one step, with no loop. Code reads more like the maths on a page. It also runs fast, because the work is done by tuned code underneath.

R came out of a university in the 1990s, and people who work on stats love it. It has thousands of free add-ons for every kind of test and chart. Many research papers are written with R doing the numbers.

MATLAB has been sold since the 1980s, and many schools for engineers teach it. It comes with add-on kits for sound, pictures and control. The licence costs money. That is why many teams move to Python or Julia in time.

Julia appeared in 2012. It was built to end a common pain. People wrote a quick version in an easy language, then wrote it all again in C for speed. Julia builds each function the first time it runs, so the easy version is already fast.

Python does much of the same work with add-ons such as pandas. It is now the most common choice for data work. These three stay strong where they began. R leads in stats, MATLAB in building and testing machines, and Julia in heavy science.

The trap when moving between them is the starting index. data[1] is the first item in R, Julia and MATLAB, but the second item in Python. Code moved across without care is off by one.

r
prices <- c(2.5, 4.0, 3.5)
prices * 2        # 5.0 8.0 7.0, no loop needed
mean(prices)      # 3.333333
prices[1]         # 2.5, R counts from 1
In R, one line doubles every price. The first item is prices[1], not prices[0].
Data languages work on the whole list in one step. They also count the first item as 1.

Worked example

Emma moves a model from MATLAB to Python

Emma ports a 600 line MATLAB model to Python to save on licences. Every result comes out shifted by one row.

Each data(1) in MATLAB should have become data[0] in Python. She fixes 37 places, and the results match to 6 decimal places.

The words for this lesson3

Check yourself

In R, Julia and MATLAB, what is the index of the first item in a list?

Finished this lesson?

Marking it complete also marks its 3 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.