Re: [R] permutates and/or samples a matrix

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Thu, 31 Jan 2008 13:44:46 +0000 (UTC)

On 31 Jan 2008, you wrote in gmane.comp.lang.r.general:

> Hi,
>
> sample(x) only permutates and/or samples from a vector, which I
> can't use for a matrix. Please help.
 

You just feed sample(.) a "redimensioned" object. If you need to do it programmatically just multiply the dimensions of the matrix to create a length for the working vector.

> xm<-rnorm(25)
> xmtx<-matrix(xm,dim<-c(5,5))
> samp<-sample(as.matrix(xmtx,dim<-c(1,25)))
> samp

#output of 25 numbers elided

> samp<-sample(as.matrix(xmtx,dim<-c(1,25)),10)
> samp

 [1] 0.26421745 0.63888288 1.06176705 -1.56074510 -0.72471549 - 0.38743020
 [7] -0.68765683 1.18081648 -1.51566762 0.07560708

-- 
David Winsemius

______________________________________________
R-help_at_r-project.org 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 Thu 31 Jan 2008 - 14:00:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 31 Jan 2008 - 16:30:11 GMT.

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

list of date sections of archive