Open GaryBAYLOR opened 9 years ago
This function redefine the use of "[". When the index goes beyond the length of the vector, it just restart from beginning.
`[` <- function(x, k) { n <- length(x) k <- k %% n if(k == 0) k <- n subset(x, 1:n == k) } > x [1] 3 2 4 5 1 > x[1] [1] 3 > x[2] [1] 2 > x[3] [1] 4 > x[4] [1] 5 > x[5] [1] 1 > x[6] [1] 3 > x[7] [1] 2
This function redefine the use of "[". When the index goes beyond the length of the vector, it just restart from beginning.