[R] permutate elements in a vector

Jean V Adams
Thu, 01 Dec 2011 13:36:39 -0000

Wendy wrote on 12/01/2011 04:27:09 AM:

> Hi all,
>
> I have a vector, e.g., A = c(10, 20, 30, 40). This 4 numbers have 4! =
24
> different combination. I want to generate a matrix with one combination
in
> one row, so the output would be
>
> B =
> 10 20 30 40
> 10 40 20 30
> ...
>
> Does anyone know how to do this easily in R? Thank you very much.
>
> Wendy


This has been asked and answered in earlier posts.  Search R-Help for
permutations.  Here is one solution (see below).

Jean


http://tolstoy.newcastle.edu.au/R/e8/help/09/10/0983.html

From: David Winsemius
Date: Sat, 10 Oct 2009

require(combinat)
permn(c(23,46,70,71,89))

	[[alternative HTML version deleted]]