On Wed, 2 Nov 2016, Sven Schreiber wrote:
Hi,
it doesn't look as if there ever was an answer (holiday season...).
But I think Henrique is right -- and myself have stumbled across a similar
problem, namely when selecting/slicing out a submatrix. Example:
<hansl>
matrix m = {1, 2, 3}
colnames(m, "one two three")
print m
matrix m2 = m[, 1:2]
print m2 # no header anymore
</hansl>
cheers,
sven
While we're on the subject: I don't remember exactly when, but someone
brouht up the fact that it's not immediate, in Hansl, to delete certain
row/columns from a matrix. Suppose for example that I wanted to modify a
matrix X by killing column 4. The best way to do this would be
<hansl>
X = X[,1:3] ~ X[,5:]
</hansl>
which, however, gets a little awkward if the column you want to drop is
the first or the last one. Ok, you may go
<hansl>
scalar k = 4
if k==1
X = X[,2:]
elif k==cols(X)
X = X[,1:k-1]
else
X = X[,1:k-1] ~ X[,k+1:]
endif
</hansl>
or
<hansl>
X = selifc(X, !(seq(1,cols(X)).=k))
</hansl>
but neither is elegant and transparent at the same time. Worse still,
imagine I wanted to drop column 2, 3 and 5. Ok, you have the übergeekish
<hansl>
e = {2,3,5}
X = selifc(X, !(maxc(seq(1,cols(X)).=e')))
</hansl>
but I wouldn't be averse to introducing a function pair like killcol(X, e)
and killrow(X, e). Opinions?
-------------------------------------------------------
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
-------------------------------------------------------