Am 03.11.2016 um 20:02 schrieb Allin Cottrell:
I've made start on implementation. Supported so far: a single
negative
index per dimension, as in Berend's example, and also an all-negative
index-vector per dimension. An exclusion in one dimension can be
combined with an arbitrary "positive" specification in the other.
That's very nice!
<hansl>
matrix A = mshape(seq(1,12), 3, 4)
A
eval A[-1,-2]
eval A[1:2,-2]
eval A[{1,3},-2]
eval A[,{-1,-3}]
eval A[2:3,{-1,-3}]
eval A[2:3,seq(-1,-3)]
</hansl>
I just tested that the form "-{2,3}" to represent an all-negative index
vector also works.
(As in Jack's follow-up posting, you can't mix positive and
negative
values in a single index-vector.)
Right -- but could there be a more specific error message maybe? I'm
getting "index out of bounds", which is understandable but still a
little off track I'd say, because each individual entry (-1 and 2) is OK
under this new syntax feature.
Not sure about exclusionary "from:to" ranges. The R syntax
is
"-(from:to)". Supporting that would require additional changes to the
parser. Maybe just tell people to use seq() for this?
An expression "(from:to)" with round parentheses looks a little
un-hanslish indeed.
However, what would be the problem with curly braces in "{from:to}" (my
previous suggestion)? Intuitively I'd say that after an opening brace
"{" it's 100% obvious that we're in a matrix expression where the colon
":" hasn't been allowed so far. So it looks as if it would be relatively
straightforward to teach the parser to recognize the colon as indicating
an integer sequence and translate it to "seq(from,to)".
This is of course unrelated to the original column/row dropping feature,
it would be a general alias for seq() (or more precisely, for the
two-argument variant of seq). I think it would increase hansl's coolness
factor ;-)
thanks,
sven