On Mon, 8 Jul 2019, Sven Schreiber wrote:
Am 08.07.2019 um 08:12 schrieb Riccardo (Jack) Lucchetti:
> On Sun, 7 Jul 2019, Allin Cottrell wrote:
>
>>> Do you guys like the idea?
>>
>> Yes. It's now in git.
>
> Thanks; besides, we could extend Sven's idea to mshape() and make the
> third argument optional (defaulting to 1, of course). Is this a good idea?
Not sure I like the default 1. If X has exactly r elements,
mshape(X,r,1) can be easily achieved by vec(X), right? And it seems to
me it is not a very standard case to use mshape(X,r,1) for r != nelem(X).
In fact, what I had in mind is the idiom "mshape(NA, r, c)", taht I use a
lot for initialising matrices.
What might be nice is to make mshape more clever, to automatically
determine the necessary number of columns c. Example:
matrix X = ones(3,2)
m1 = mshape(X,2,3) # old explicit syntax
m2 = mshape(X,2) # proposed
That is, if the 3rd arg is omitted, mshape would try to calculate c =
nelem(X) / r. (It would throw an error if the result is not an integer.)
I quite like this; actually, in case r*c is not an exact multiple of
nelem(X), we could allow for "wrapping", that is
mshape(seq(1,4), 3)
could return
1 4
2 1
3 2
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------