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" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
08/18/2006 05:16 PM
To
"'Jesse Albert Canchola'" <[EMAIL PROTECTED]>, "'r-help'"
<[email protected]>
cc
Subject
Re: [R] Permutations with replacement
> -----Original Message-----
> From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
> 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
______________________________________________
[email protected] 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
______________________________________________
[email protected] 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.