Why do vector indices in R start with 1, instead of 0? [closed] Why do vector indices in R start with 1, instead of 0? [closed] arrays arrays

Why do vector indices in R start with 1, instead of 0? [closed]


FORTRAN is one language that starts arrays at 1. Mathematicians deal with vectors that always start with component 1 and go through N. Linear algebra conventions start with row and column numbered 1 and go through N as well.

C started with zero because of the pointer arithmetic that was implicit underneath. Java, JavaScript, C++, and C# followed suit from C.


Vectors in math are often represented as n-tuples, elements of which are indexed from 1 to n. I suspect that r wanted to stay true to this notation.


Frank, I think you were misinterpreting what you saw when you typed arr[0]. The numeric(0) just means that the result is a numeric vector with no elements. It does not mean that the type of the vector is being "stored" in element 0. You would have gotten the same result if you had typed, for example, arr[arr > 30]. No element meets that condition, so the result vector has no elements. Likewise, no element has index 0. This is intentional, and has nothing to do with the 0 space being used for something else.