This may be redundant, but I could not find a similar question about SO.
Is there a shortcut to get the last n elements / records in a vector or array without using the length of the vector in the calculation?
foo <- 1:23
> foo [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Let them say that the last 7 entities are needed, I want to avoid this cumbersome syntax:
> foo[(length(foo)-6):length(foo)] [1] 17 18 19 20 21 22 23
Python has foo[-7:] . Is there something similar in R? Thanks!
harkmug
source share