ABSTRACT

Both R and MATLAB can perform vectorized computations, where iteration over the elements of a vector or matrix is performed implicitly, i.e., internally. This is much more efficient than writing explicit “for” loops, which run very slowly due to both platforms being interpreted (rather than compiled) languages. The C functions in this chapter call a random-number generator. The details of such calls are generally very specific to the operating system and/or C compiler people are using. The advantage of using the C library's random number generator is that, other than the interface function that people call from R, their C code will be more portable in the sense that they can use it as part of a stand-alone C program. There are two other ways of calling C code from R:.Call and.External. They require more complex C code to handle function arguments, set up return values, and handle memory management.