[R] converting MATLAB -> R | element-wise operation

Berwin A Turlach berw|n@tur|@ch @end|ng |rom gm@||@com
Wed Feb 28 10:42:27 CET 2024


On Tue, 27 Feb 2024 13:51:25 -0800
Jeff Newmiller via R-help <r-help using r-project.org> wrote:

> The fundamental data type in Matlab is a matrix... they don't have
> vectors, they have Nx1 matrices and 1xM matrices.

Also known as column vectors and row vectors.  :)
 
> Vectors don't have any concept of "row" vs. "column". 

They do in (numerical) linear algebra.  And MATLAB was written by
numerical analysts for numerical analysts. :-)  So they distinguish
between row and column vectors.

GAUSS also distinguishes between row and column vectors.

R (and S) does not distinguish between row and column vectors, and is
in this aspect quite unique among the groups of vector-oriented
programming languages (AFAICT).  But  treating every vector as a column
vector, together with the recycling rule, allows for the easy coding of
the matrix/vector calculations that one (mostly) comes across in
statistical computing.  For the rare occasion when this is not true the
sweep() command is provided, typically remembered once one was bitten
by the lack of distinction between row and column vectors. :)

Cheers,

	Berwin



More information about the R-help mailing list