[R] Permutations with replacement

Daniel Nordlund res90sx5 at verizon.net
Sat Aug 19 02:16:37 CEST 2006


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]
> On Behalf Of Jesse Albert Canchola
> Sent: Friday, August 18, 2006 1:02 PM
> To: r-help
> Subject: [R] Permutations with replacement
> 
> Is there a simple function or process that will create permutations with
> replacement?
> 
> I know that using the combinat package
> 
> ###### begin R code ######
> > library(combinat)
> > m <- t(array(unlist(permn(3)), dim = c(3, 6)))
> 
> # we can get the permutations, for example 3!=6
> # gives us
> 
> > m
>      [,1] [,2] [,3]
> [1,]    1    2    3
> [2,]    1    3    2
> [3,]    3    1    2
> [4,]    3    2    1
> [5,]    2    3    1
> [6,]    2    1    3
> ###### end R code ##########
> 
> I'd like to include the "with replacement possibilities" such as
> 
> 1,1,3
> 1,1,2
> 2,3,3
> 
Isn't what you want just sampling with replacement?

  x <- c(1,2,3)
  sample(x,3,replace=TRUE)

Hope this is helpful,

Dan

Dan Nordlund
Bothell, WA  USA



More information about the R-help mailing list