R/permute.R

Defines functions permute

Documented in permute

permute <- function (a) {
  aa <- matrix(NA, length(a)-1, length(a))
  for (i in 1:(length(a)-1)) {
    aa[i,] <- a[c((i+1):length(a), 1:i)]
  }
  return(aa)
}

# The above function computes the all possible 
# combinations of a vector a. For example,
# for a <- 1:3, the result will be a matrix
# of 2*3:
# 2 3 1
# 3 1 2

Try the LPE package in your browser

Any scripts or data that you put into this service are public.

LPE documentation built on Nov. 1, 2018, 3:03 a.m.