This is not trivial. There is a really nice algorithm (should be simple to code up) due to Persi Diaconis, and described in example 1.22 (page 1-14) of Joseph Chang's notes on Markov chains available at http://www.stat.yale.edu/~jtc5/251/mc.pdf
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Yann Clough Sent: Wednesday, February 09, 2005 8:28 AM To: Peter Dalgaard; [email protected] Subject: Re: [R] randomisation I am working on an ecological problem and dealing with a matrix where rows correspond to samples, and columns correspond to species. The values in the matrix are recorded abundances of the organisms. I want to create a series of randomised datasets where total abundances per sample (rowSums) and per species (colSums) are equal to those in the dataset of my observations. Simple example of the kind of thing I have: matrix(c(1,0,2,10,1,3,5,6,7,1,0,0),nrow=4, ncol=3,by=row) # observed data rowSums(tempmatrix) #individuals per location, colSums(tempmatrix) #individuals per species example of a matrix which complies with the two restrictions: tempmatrix2=matrix(c(1,0,2,11,0,3,5,6,7,0,1,0),nrow=4, ncol=3,by=row) rowSums(tempmatrix2) colSums(tempmatrix2) hope this is clear Cheers Yann *************************** Yann Clough Fachgebiet Agraroekologie Waldweg 26 D-37073 Goettingen Tel: 0551/39-2157 email: [EMAIL PROTECTED] www: http://wwwuser.gwdg.de/~uaoe/mitarbeiter/y_clough.htm ______________________________________________ [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 ______________________________________________ [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
