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

2024-03-01 Thread Martin Maechler
> 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 wrote: >> The fundamental data type in Matlab is a matrix... they >> don't have vectors, they have Nx1 matrices and 1xM >> matrices.

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

2024-02-28 Thread Richard O'Keefe
The first vector-oriented programming language I ever learned or used was APL, and APL makes *no* distinction between row vectors and column vectors. It has rank-0 (scalar), rank-1 (vector), rank-2 (matrix), rank-3 ... and so on arrays. A rank-1 array is a rank-1 array is a rank-1 array and

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

2024-02-28 Thread peter dalgaard
Agree that sweep is the tool here. (If you think it is clunky, check how more general array-sweep operations can be done in Matlab.) However, it isn't really true that sweep isn't moving things around. Notice the call to aperm() at the end of the code for sweep(): perm <- c(MARGIN,

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

2024-02-28 Thread Berwin A Turlach
On Tue, 27 Feb 2024 14:54:26 -0500 Evan Cooch wrote: > So, trying to convert a very long, somewhat technical bit of lin alg > MATLAB code to R. Most of it working, but raninto a stumbling block > that is probaably simple enough for someone to explain. On

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

2024-02-28 Thread Berwin A Turlach
On Tue, 27 Feb 2024 13:51:25 -0800 Jeff Newmiller via R-help 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.

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

2024-02-27 Thread Bert Gunter
... and here is a more or less direct translation of the Matlab code that should now be obvious given your previous responses: > m <- matrix(1:6, nr=2, byrow = TRUE) ## Matlab order > m [,1] [,2] [,3] [1,]123 [2,]456 > sweep(m, 2, 2:4, "/") [,1] [,2] [,3]

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

2024-02-27 Thread Jeff Newmiller via R-help
Why anything but sweep? The fundamental data type in Matlab is a matrix... they don't have vectors, they have Nx1 matrices and 1xM matrices. Vectors don't have any concept of "row" vs. "column". Straight division is always elementwise with recycling as needed, and matrices are really vectors

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

2024-02-27 Thread Evan Cooch
So, trying to convert a very long, somewhat technical bit of lin alg MATLAB code to R. Most of it working, but raninto a stumbling block that is probaably simple enough for someone to explain. Basically, trying to 'line up' MATLAB results from an element-wise division of a matrix by a vector