Dear all,
I would like to create a k,n matrix which that will include 


- k random elements with value 1
-all rest zeros

-one single "1" in each row 

- each column will have maximum one "1"


so far I have a so stupid function that with nested while tries to fit k 
numbers randomly in a row by row fashion, checking also if the c column rule is 
violated. In that case there is also another loop that will try to find a new 
solution.

That way it takes ages, as it is natural to complete a matrix of 300,512 as the 
new ones conflict all the time.

I am trying to find an easy way to make this algorithm way simpler that will 
help me reduce the time needed.
I was thinking then if R can help me by shuffling number from 1  to 300 
randomly, so to avoid the first loop that does that goes row by row.. and then 
find an easy way to check if the column rule is violated.

Do you think that you can spend some time help me?

Have a nice weekend

Regards
Alex

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to