3
Matrices and Vectors
3.1 Overview
Both MATLAB and R
can work directly with vectors and with m x
n matrices (with the usual convention that m specifies the number of rows and n the number of columns). Both platforms support vectorized computations, i.e., expressions that implicitly operate on entire vectors or matrices. However, there are some important differences between the two.
A key difference in syntax is that
R
uses square brackets to delimit matrix subscripts (e.g.,A[2,3])
, while MATLAB uses parentheses (e.g.,A(2,3))
.R
's syntax has the advantage here because when reading MATLAB code, it is not immediately apparent whetherg(2,3)
is accessing an element of a matrixg
, or calling a functiong
with two parameters.In R, ...
Get R and MATLAB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.