[R] loop not working my way
Laz
lmramba at ufl.edu
Sat Oct 19 23:09:39 CEST 2013
Thank you so very much!
It works like a charm !!!
Regards,
Laz
On 10/19/2013 5:03 PM, Rui Barradas wrote:
> fun <- function(n = 10){
> matd <- matrix(sample(1:30,30, replace=FALSE), ncol=5, nrow=6)
> res <- list(mat = NULL, Design_best = matd, Original_design = matd)
> trace <- sum(diag(matd))
> res$mat <- rbind(res$mat, c(trace = trace, iterations = 0))
> for(i in seq_len(n)){
> matd <- matrix(sample(1:30,30, replace=FALSE), ncol=5, nrow=6)
> if(sum(diag(matd)) < trace){
> trace <- sum(diag(matd))
> res$mat <- rbind(res$mat, c(trace = trace, iterations = i))
> res$Design_best <- matd
> }
> }
> res
> }
>
> fun()
> fun(20)
More information about the R-help
mailing list