One reason languages like Python and R are slow is that they have to continually check what they’re supposed to be doing, as they’re doing it. Take the simplest possible code, something like:
a + b
What does this do? Well, it depends on what a and b are. They could be numbers, as in 3 + 5 == 8, but you can’t assume that: Python can also add strings, like "foo" + "bar" == "foobar", or matrices, and you need a different algorithm for each kind of addition. In fact you can customise how + works, and it could do more or less anything. So calculating a + b is a multi-step process: check what a is, check what b is, figure out how to add them, then find, load and execute that code. If you’re adding two numbers, the core work is a single CPU instruction that takes about a nanosecond to execute. But all the bookkeeping takes about a hundred times longer. (Imagine someone whose to-do list is far too specific, with hundreds of items for different parts of a single task – you’d spend most of your time managing the list itself!)