3 ms·
R's indexing is not only 1-based, it's inclusive on both ends. So indexing from 3 to 5 actually gets you elements 3, 4, and 5. I've programmed a bunch with both
by rcthompson 3y ago
R's indexing is not only 1-based, it's inclusive on both ends. So indexing from 3 to 5 actually gets you elements 3, 4, and 5. I've programmed a bunch with both R and 0-based languages and I greatly prefer R's way of doing indexing.
- trealira 3y agoI'm pretty sure it's like this in Pascal, too. Which makes sense, since it's the only way to reasonably index 1-based arrays. For example, you'd expect the following code to set arr to the set "1, 2, 3, 4, 5", not to leave the last element uninitialized. var arr: array [1 .. 5] of integer; begin for i := 1 to 5 do arr[i] := i end; Normally you would write "for i := low(arr) to high(arr)". I just wrote the numbers "1 to 5" to be explicit here.