David Winsemius <[EMAIL PROTECTED]> wrote : > On 31 Jan 2008, Stanley wrote:
>> 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 > Looking at Csardi's reply made me realize I may have incorrectly characterized your experience. I thought you said you had been unable to use sample() from a matrix. Sample appears to return elements from a matrix without complaint without the redimensioning step. Sorry, I must have misunderstood your question. -- David Winsemius ______________________________________________ R-help@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.