Currently, I have
extract_modulo = function(x, n, fn=`[`) fn(x, (n-1L) %% length(x) + 1L)
`%[mod%` = function (x, n) extract_modulo(x, n)
And then:
seq(12) %[mod% 14
#[1] 2
Is this already built into R somewhere? I would think so, because R has several functions that recycle values (e.g., paste
). However, I'm not finding anything with help('[[')
, ??index
, or ??mod
. I would think an R notation for this would be something like seq(12)[/14/]
or as.list(seq(12))[[/14/]]
, for example.