March 2018
Beginner to intermediate
570 pages
13h 42m
English
Were you wondering why R is so adamant about keeping the elements of vectors in adjoining memory locations? Well, if R didn't, then traversing a vector (like when you apply a function to each element) would require hunting around the memory space for the right elements in different locations. Having the elements all in a row gives us an enormous advantage, performance-wise.
To fully exploit this vector representation, it helps to use vectorized functions, which we were first introduced to in Chapter 1, RefresheR. These vectorized functions call optimized and blazingly fast C code to operate on vectors instead of on the comparatively slower R code. For example, let's say we wanted to square each height in the all.us.women vector. ...