[R] manipulating elements of a matrix

Vumani Dlamini dvumani at hotmail.com
Fri May 9 15:49:57 CEST 2003


Dear R users:

I have the following matrix.

0 1 1
0 1 0
2 1 0
3 0 0

I would like to spread the matrix such that whenever the row sum is greater 
than 1 the row is repeated the number of times given by the row sum. 
Furthermore I would like to split the following cases:

0 1 1
such that it map to the following matrix

0 1 0
0 0 1

such that each row adds up to 1.

I have no problems with cases like c(3,0,0) using "lapply" but I have no 
splitting cases of the form c(1,1,0) and thats where I need your help.

Thanking you as always.


Vumani Dlamini




More information about the R-help mailing list