<html><body><p>Hi<br /><br />Adopting the solution outlined in this post<br /><br />
http://stackoverflow.com/questions/15858569/randomly-permute-rows-columns-of-a-matrix-with-eigen<br /><br />I can produce random column and row permutation replicates of matrices using RcppEigen:<br /><br />permmatrix<-'<br /> List permmatrix(NumericMatrix Xr){<br /><br /> RNGScope scope;<br /> const Eigen::Map X(as >(Xr));<br /><br /> int nr = X.rows();<br /> int nc = X.cols();<br /><br /> // Permute Columns<br /> Eigen::PermutationMatrix permc(nc);<br /> permc.setIdentity();<br /> std::random_shuffle(permc.indices().data(), permc.indices().data()+permc.indices().size());<br /> Eigen::MatrixXd Xpc = X * permc; <br /><br /> // Permute Rows<br /> Eigen::PermutationMatrix permr(nr);<br /> permr.setIdentity();<br /> std::random_shuffle(permr.indices().data(), permr.indices().data()+permr.indices().size());<br /> Eigen::MatrixXd Xpr = permr * X;<br /><br /> return(List::create(Named("X")=X,Named("Xpc")=Xpc,Named("Xpr")=Xpr));<br /> }'<br /> <br /><br />library(RcppEigen)<br />permMatrix<-cppFunction(permmatrix,depends="RcppEigen")<br /><br />permMatrix(matrix(1:12,3,4))<br />$X<br /> [,1] [,2] [,3] [,4]<br />[1,] 1 4 7 10<br />[2,] 2 5 8 11<br />[3,] 3 6 9 12<br /><br />$Xpc<br /> [,1] [,2] [,3] [,4]<br />[1,] 1 7 10 4<br />[2,] 2 8 11 5<br />[3,] 3 9 12 6<br /><br />$Xpr<br /> [,1] [,2] [,3] [,4]<br />[1,] 2 5 8 11<br />[2,] 1 4 7 10<br />[3,] 3 6 9 12<br /> <br />The problem is that I cannot (or do not know how to) use the R random seeding mechanism to make the permutation resampling process<br />reproducible. I would appreciate any advice on this matter (e.g., replacing std::random_shuffle with a suitable Rcpp function or to be pointed to<br />existing solutions ). <br /><br /><br />Sincerely,<br />Kouros Owzar<br />Duke University<br /><br /><br />> print(sessionInfo(),locale=FALSE)<br />R version 3.0.1 (2013-05-16)<br />Platform: x86_64-pc-linux-gnu (64-bit)<br /><br />attached base packages:<br />[1] stats graphics grDevices utils datasets methods base <br /><br />other attached packages:<br />[1] RcppEigen_0.3.1.2.1 Matrix_1.0-12 lattice_0.20-15 <br />[4] Rcpp_0.10.3 <br /><br />loaded via a namespace (and not attached):<br />[1] grid_3.0.1 tools_3.0.1<br /><br />,eigen::dynamic>,eigen::dynamic></p></body></html>