Skip to content
Back to formatted view

Raw Message

Message-ID: <1322744758343-4128227.post@n4.nabble.com>
Date: 2011-12-01T13:05:58Z
From: Berend Hasselman
Subject: permutate elements in a vector
In-Reply-To: <1322735229427-4127821.post@n4.nabble.com>

Wendy wrote
> 
> 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
> 

You want permutations not combinations.

library(e1071)
permutations(4) * 10

or 

library(gtools)
A <- 10*(1:4)
permutations(4,4,A)

Berend


--
View this message in context: http://r.789695.n4.nabble.com/permutate-elements-in-a-vector-tp4127821p4128227.html
Sent from the R help mailing list archive at Nabble.com.