(1:10)[2:5]
# [1] 2 3 4 5
(1:10)[2 + 1:5 + 1]
# [1] 4 5 6 7 8
(1:10)[(2 + 1):(5 + 1)]
# [1] 3 4 5 6
(1:10)[10 + 1:5 + 1]
# [1] NA NA NA NA NA
I am learning how list access works in R. The second case from the above looks weird. Can someone explain how that pattern is working ?
(1:10)[2 + 1:5 + 1]