Skip to content
Prev 367550 / 398500 Next

Matrix

Clever, Don.

Here's a more explicit approach that generalizes (if I haven't made
any dumb errors):

x <- c(1:5,10:12)
## generate vector of indices by outer and %%
i <- seq_along(x)
nc <- 4 ## number of columns desired
## get subscripting indices via outer() and %%
indx <- outer(i,rev(i),"+") %% (length(x))[,seq_len(nc)]+1
matrix(x[indx],ncol = nc)

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Mar 6, 2017 at 9:46 AM, MacQueen, Don <macqueen1 at llnl.gov> wrote: