Suppose I have the following array:
a <- sample(letters,100,replace=TRUE)
You can use
embed(a, 3), this gives a matrix with columns
in that order.
To reverse the column order use matrix syntax
res = embed(a, 3)[, 3:1]
If you want arrows printed between the columns, then
do.call(paste, c(split(res, col(res)), sep = " -> "))
is one way. This is probably better than
apply(res, 1, something), performance-wise, since this is vectorized while
apply would loop over rows.
I was hoping to say something useful about how to find obscure functions in R, but came up mostly blank on how
embed might be found. Maybe...