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

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Fri Mar 1 09:49:19 CET 2024


>>>>> Berwin A Turlach 
>>>>>     on Wed, 28 Feb 2024 17:42:27 +0800 writes:

    > 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.

There are *vectors* and they belong to a vector space and that's it.
(and yes, arrays of a given rank and dimensions also are
 elements of a vector space, and hence matrices are, and then
 indeed, a 3x1 matrix and a 1x3 matrix are *not* members of the
 same vector space -- even though the two vector spaces are
 isomorphic to each other)

The matlab induced --> applied linear algebra / math
"column- and row-vectors"  have been convenient because then
everything is a matrix (or scalar), and that fits well with a
product called "matlab" which is short for "matrix lab(oratory)".
BUT they are  mathematically confusing and therefore in my view
very undesirable terminology.

I'm very very strongly with Jeff that "the only" consistent
language would be to call them 1-row matrix and 1-column matrix,
because that's what they are, well defined and perfect within 
the well defined math realm of linear algebra.

Yes, matrix-vector calculus , scalar products, bilinear forms, ...
can be generalized in such ways that 1-row matrices and 1-column
matrices can be treated equivalently to vectors and vice versa
.. and that is sometimes convenient. 

Still, the "column-vector"  and "row-vector"  terms have
lead to much confusion in my view,
because really  Nx1  or  1xM  are dimensions of matrices and
*not* of any 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).

I agree. And that's good -- because "vectors are vectors" aka
"a rank-1 array is a rank-1 array is a rank-1 array" (Richard O'Keefe)

    > 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

Martin



More information about the R-help mailing list