[R] help : matrix row/column random mixing

Dave Roberts droberts at montana.edu
Wed Nov 2 23:13:19 CET 2005


There are several bootstrap packages available at CRAN that probably 
provide an elegant solution, but simply permuting the matrix is pretty easy

 > data <- matrix(1:100,nrow=5) # matrix of 5 rows and 20 columns
 > x <- data[sample(1:5),] # permute the rows
 > y <- x[,sample(1:20)] # permute the columns

to really scamble the matrix

 > z <- matrix(sample(data),nrow=5)

Dave R.

booop booop wrote:
> Could anybody help me in mixing the matrix values randomly (first rows and then columns)...
>  
> for eg  putting the 1 st row in the place of 3 rd and 3rd in place of 4 th and 4th in place of 1st row ...something like this in columns also..
>  
> Please suggest me some ways..
>  
> thanks a lot..
>  
> with regards,
> boopathy.
> 
> 		
> ---------------------------------
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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
> 
> 


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David W. Roberts                                     office 406-994-4548
Professor and Head                                      FAX 406-994-3190
Department of Ecology                         email droberts at montana.edu
Montana State University
Bozeman, MT 59717-3460




More information about the R-help mailing list