Re: [R] Making a point-sampling matrix

2012-02-04 Thread andrija djurovic
Hi. If I understood you correctly here is one approach to your solution: > k <- 5 > mat <- diag(1,nrow=k,ncol=k) > set.seed(10) > samp <- mat[sample(1:k,3,rep=FALSE),] > samp [,1] [,2] [,3] [,4] [,5] [1,]00100 [2,]01000 [3,]00010 > #

[R] Making a point-sampling matrix

2012-02-04 Thread Alaios
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