榎本剛
October 31, 2024
Rにない函数。headとtailを使う。
head
tail
shift <- function(x, n) { if (n == 0) { x } else { c(tail(x, n), head(x, -n)) } } shift(1:9,3)
[1] 7 8 9 1 2 3 4 5 6
shift(1:9,-2)
[1] 3 4 5 6 7 8 9 1 2