3 ms·
> a[1-3] [1] 1 3 > a[[1-3]] Error in a[[1 - 3]] : attempt to select more than one element The first line evaluates to a[-2]. I think what the author mean
by fxj 10y ago
> a[1-3]
[1] 1 3
> a[[1-3]]
Error in a[[1 - 3]] : attempt to select more than one element
The first line evaluates to a[-2]. I think what the author meant was a[1:3].
a[[-2]] gives an error, a[[2]] is valid R.
- capnrefsmmat 10y agoa[-2] is valid R syntax. A negative index means that element is omitted from the result, so a[-2] is a without the second element.