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

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

2024-02-27 Thread Richard M. Heiberger
> t(t(NN)/lambda) [,1] [,2] [,3] [1,] 0.5 0.667 0.75 [2,] 2.0 1.667 1.50 > R matrices are column-based. MATLAB matrices are row-based. > On Feb 27, 2024, at 14:54, Evan Cooch wrote: > > So, trying to convert a very long, somewhat technical bit of lin alg > MATLAB code to R.

[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