On Wed, Apr 15, 2026 at 6:49 AM Riccardo (Jack) Lucchetti
<p002264(a)staff.univpm.it> wrote:
On 14/04/2026 21:14, Sven Schreiber wrote:
Am 13.04.2026 um 22:50 schrieb Cottrell, Allin:
It strikes me that in some cases it might be convenient to be able to
extract a column from a gretl matrix that has column-names attached by
name rather than column-number. The primary case I have in mind is a
matrix returned by a function (or in a bundle returned by a function),
where the columns basically represent series. So, given
matrix M = some_func(some_args)
series some_name = M[,4]
one could do, say,
matrix M = some_func(some_args)
series some_name = M[,"forecast"]
Any thoughts on this? If the idea seems attractive I can see about
implementing it.
Yes it does seem attractive. A follow-up question would be: what's the error if the
name doesn't exist? Index out of bounds?
Another thought: Instead of having named columns collected in a matrix, the same columns
could already be stored inside a bundle with the same names, and then would be accessible
by name without the square brackets and the quotes, like B.forecast. On the other hand, if
the columns are in the same matrix, that would ensure that their lengths are equal, which
might be an advantage.
I find the idea _very_ attractive too. Beside Sven's remakes, there are other two
points that are IMO worth considering:
why not rows too?
how about string arrays for multiple selection?
OK, for those working with gretl git here's a little test script for
new functionality. Rownames are also supported, but not yet arrays of
matrices. This is not yet in the snapshots but that should happen
tomorrow.
<hansl>
set seed 765545431
matrix M = mnormal(4,3)
cnameset(M, "one two three")
print M
matrix c = M[,"two"]
print M c
rnameset(M, "a b c d")
eval M["c","two"]
matrices MM = defarray(M, I(3))
eval MM[1][,"three"]
bundle b = _(M)
eval b.M[,"three"]
matrix a = {1.5}
cnameset(a, "c1")
rnameset(a, "r1")
a
eval a["c1"]
eval a["r1"]
# and write mode
M[,"three"] = seq(1,4)'
M
MM[1][,"three"] = seq(1,4)'
eval MM[1][,"three"]
</hansl>
Allin