% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/perm.R
\name{perm}
\alias{perm}
\title{Generate all m-permutations of n without repetition}
\usage{
perm(n, m, vals = 1:n, noreverse = 0)
}
\arguments{
\item{n}{total # of elements}

\item{m}{# of elements to choose}

\item{vals}{a vector of values to be permuted}

\item{noreverse}{= 1 to remove reverse-equivalent rows \cr
= 2 to check the result}
}
\value{
A matrix of the size P(n,m) x m.
}
\description{
Generate all m-permutations of n without repetition
}
\details{
The recursive algorithm below is used.
\preformatted{
  res=NULL
  for( i in 1:n )\{
    res <- rbind(res, cbind(vals[i], Recall(n - 1, m - 1, vals[-i])))
  \}
}

The method of removal of reverse-equivalent rows comes from
the answer to stack overflow question: \cr
"How to remove reverse rows in a permutation matrix?" \cr
by obchardon at Sep 15, 2020 at 7:46 \cr
https://stackoverflow.com/questions/63896177/how-to-remove-reverse-rows
-in-a-permutation-matrix
}
\examples{
n <- 5
for( m in 1:n )
 Print( m, perm(n,m), comb(n,m) )
 
 Print( perm(3,3), perm(3,3,,1) )

}
