Re: [R] Generating a matrix

2013-12-03 Thread arun
HI, You could try:  mat1 <- matrix(0,8,8)  diag(mat1) <- 5  mat2 <- apply(mat1,2,rev)  diag(mat2) <- 5  indx<- which(mat2==5)  mat2[indx[indx%%8==1]+1] <-1 mat2[indx[indx%%8==0]-1] <-1  mat2[indx[!(indx%%8==0 |  indx%%8==1)]-1][mat2[indx[!(indx%%8==0 |indx%%8==1)]-1]==0] <- 1  mat2[indx[!(indx%%8

Re: [R] Generating a matrix

2013-12-03 Thread David Carlson
We don't do homework assignments on the list, but one answer requires no loops and an understanding of the various ways R uses vectors for indexing: ?"[" - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -Orig

Re: [R] generating a matrix after a for loop..

2009-11-28 Thread Greg Snow
Let me see if I understand your question. You want to run your simulation function (mclustSim) several times and collect the resulting vector from each run into a matrix. Is that correct? In that case you can just you the replicate command (as long as your function returns the same length vecto