In R, when I add 0
(or a variable that has a value of 0
) to each index of a slice, I end up with a result that is one element longer than I expect.
Why is this, and how can I achieve the 1 2 3 4 5
result I expect?
my_vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
my_vec[1 : 5]
my_vec[1 + 0 : 5 + 0]
returns
1 2 3 4 5 # my_vec[1 : 5]
1 2 3 4 5 6 # my_vec[1+0 : 5+0]