[R] x[0]: Can '0' be made an allowed index in R?
Martin Maechler
m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue Apr 23 14:03:08 CEST 2024
>>>>> Ben Bolker
>>>>> on Sun, 21 Apr 2024 10:23:50 -0400 writes:
> Also https://cran.r-project.org/package=Oarray (which is older and
> hence possibly more stable)
also maintained and written by a careful and really good person.
I do recommend Oarray as well.
Martin
BB> On 2024-04-21 3:55 a.m., Hans W wrote:
>> As we all know, in R indices for vectors start with 1, i.e, x[0] is not a
>> correct expression. Some algorithms, e.g. in graph theory or combinatorics,
>> are much easier to formulate and code if 0 is an allowed index pointing to
>> the first element of the vector.
>>
>> Some programming languages, for instance Julia (where the index for normal
>> vectors also starts with 1), provide libraries/packages that allow the user
>> to define an index range for its vectors, say 0:9 or 10:20 or even negative
>> indices.
>>
>> Of course, this notation would only be feasible for certain specially
>> defined vectors. Is there a library that provides this functionality?
>> Or is there a simple trick to do this in R? The expression 'x[0]' must
>> be possible, does this mean the syntax of R has to be twisted somehow?
>>
>> Thanks, Hans W.
More information about the R-help
mailing list