v <- 1:10
So I accidentally discovered that:
v[0:10] == v[1:10]
output:
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
How? First of all, I thought that R indices start with 1?
From the R language definition (section 3.4.1, "Indexing by vectors", "Integer"):
A special case is the zero index, which has null effects: x[0] is an empty vector and otherwise including zeros among positive or negative indices has the same effect as if they were omitted.
Another SO question asks "why is this useful"?, without many satisfying answers: this is an interesting question, but seems on-topic for [email protected]
rather than SO ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With