Re: [R] Permutations with replacement (final final final)

From: Jesse Albert Canchola <jesse.canchola.b_at_bayer.com>
Date: Tue 22 Aug 2006 - 03:48:54 EST


Hi Daniel,

Turns out, your code, however simple, is quite elegant for my needs (sometimes I overanalyze :O). Here is my last code to do what I need to do:

####### begin R code ########
# generate a matrix of ten thousand rows of 1-8 z <- t(matrix(rep(1:8,10000),8,10000))
library(Matrix)
# use the R sample function in a loop to sample each line with replacement zcomb=Matrix()
for (i in 1:dim(z)[1]) {

    z1 <- t(matrix(sample(z,8,replace=TRUE)))     zcomb = rbind(zcomb,z1)
    }
zcomb
####### end R code #########

Regards,
Jesse A. Canchola

"Daniel Nordlund" <res90sx5@verizon.net> Sent by: r-help-bounces@stat.math.ethz.ch 08/18/2006 05:16 PM

To
"'Jesse Albert Canchola'" <jesse.canchola.b@bayer.com>, "'r-help'" <r-help@stat.math.ethz.ch>
cc

Subject
Re: [R] Permutations with replacement

> -----Original Message-----

> From: r-help-bounces@stat.math.ethz.ch [mailto:r-help-bounces@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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

The information contained in this e-mail is for the exclusive use of the intended recipient(s) and may be confidential, proprietary, and/or legally privileged. Inadvertent disclosure of this message does not constitute a waiver of any privilege. If you receive this message in error, please do not directly or indirectly use, print, copy, forward, or disclose any part of this message. Please also delete this e-mail and all copies and notify the sender. Thank you.

For alternate languages please go to http://bayerdisclaimer.bayerweb.com



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue Aug 22 03:57:35 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 22 Aug 2006 - 04:23:20 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.