[R] the matrix of rows with specific row sums

Rajarshi Guha rxg218 at psu.edu
Tue Nov 22 22:00:19 CET 2005


On Tue, 2005-11-22 at 21:55 +0100, Serguei Kaniovski wrote:
> mdim=4
> m<-matrix(round(runif(mdim^mdim)),mdim,mdim)

One approach:

> m
     [,1] [,2] [,3] [,4]
[1,]    0    0    1    0
[2,]    0    1    1    0
[3,]    0    0    1    1
[4,]    0    0    0    0
> idx <- apply(m, 1, sum)
> m[idx,]
     [,1] [,2] [,3] [,4]
[1,]    0    0    1    0
[2,]    0    1    1    0
[3,]    0    1    1    0
>

-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
Cogito cogito ergo cogito sum 
(I think that I think, therefore I think that I am.)
-- Ambrose Bierce




More information about the R-help mailing list