Re: [R] repeating a function and combining the results

2013-12-03 Thread Bert Gunter
Arun has given you a number of ways to do what you (seem to) want. If this is fast enough, then you're done. If not, then the key to speeding things up is to do things differently. Note that a 1 x 9 matrix is a just a vector. Since each element of the vector is a "different computation", apparentl

Re: [R] repeating a function and combining the results

2013-12-03 Thread arun
HI, May be this helps: example <- function(X,n){ lst1 <- list() for(i in 1:n){ cell1 <- sample(X,1) cell2 <- sample(X,1) table1 <- cbind(cell1,cell2) lst1[[i]] <- table1 } do.call(rbind,lst1) } #or example1 <- function(X,n){ table1 <- vector() for(i in 1:n){ cell1 <- sample(X,1) cell2 <- sample