A[,{1,-2}]
Flag an error, perhaps? Yes,
A <- matrix(1:12,nrow=3)
A[,c(1,-2)] # c(1,2) is R for {1,2}
Error in A[, c(1, -2)] : only 0's may
be mixed with negative subscripts
a = 1:12
a[c(1,-2)]
Error in a[c(1, -2)] : only 0's may be mixed with negative
subscripts
a[c(0,1)]
[1] 1
one can use x[0]->numeric(0)
inside [.....] one can insert or pluses (+zero) or
minuses (+zero) only
Oleh
3 листопада 2016, 10:28:29, від "Riccardo (Jack) Lucchetti"
<r.lucchetti(a)univpm.it>:
On Thu, 3 Nov 2016, Berend Hasselman wrote:
>>> First, it would be an improvement. Second, if at all possible, I would
>>> favor some clever extension of the matrix indexing apparatus. For
>>> example (just an example, no claim of optimality), X[-3, -2] might
>>> return the matrix X without the 3rd row and the 2nd column.
>>
>> I appreciate that you said "no claim of optimality", but I don't
think
>> we should use negative indices for the purpose you indicate. Seems to
>> me the de facto standard regarding negative indices in matrix-oriented
>> languages is that they mean, "count from the end, not the beginning",
>> not "drop these rows or columns".
>
> Try this in R:
>
> A <- matrix(1:12,nrow=3)
> A
> A[-1,-2]
>
> displays A without first row and second column.
> As I expected and hoped.
I normally don't like R very much, but I must admit I find this quite
cool. I guess we could adopt the following convention with respect to
matrix slicing: positive indices mean "keep" and negative indices mean
"drop". My earlier example would just become X[,{-2,-3,-5}], or even
X[,-{2,3,5}].
As for the "from the end" convention, I guess that this is (at least in my
own experience) a rather unusual case, that can be easily handled via
mreverse() or by tricks like
# slice columns 1,3 and 4 from the end
matrix e = (cols(A) + 1) - {1,3,4}
eval A[,e]
The "minus is for dropping" convention would have the advantage of being
(a) intuitive (b) backwards compatible, though we should decide what to do
in the mixed case, eg,
A[,{1,-2}]
Flag an error, perhaps?
-------------------------------------------------------
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
-------------------------------------------------------
_______________________________________________
Gretl-devel mailing list
Gretl-devel(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel