I created custom function according to my requirement which is given below:
*selection.index<- function(ID, phen_mat, gen_mat, weight_mat, GAY){ ID = toString(ID) p<- as.matrix(phen_mat) g<- as.matrix(gen_mat) w<- as.matrix(weight_mat) bmat<- solve(phen_mat) %*% gen_mat %*% weight_mat GA<- 2.063 * t(bmat) %*% g %*% w / (t(bmat) %*% p %*% bmat)^0.5 PRE<- if(missing(GAY)){ (GA/GA) * 100 } else { (GA/GAY) * 100 } result<- list("ID" = ID, "b" = matrix(round(bmat,4), nrow = 1), "GA" = round(GA,4), "PRE" = round(PRE,4)) return(data.frame(result))}* *sc<- list()* *sc[[1]]<- selection.index(ID = 12, pmat[1:2,1:2], gmat[1:2,1:2], wmat[1:2,1])* *sc[[2]]<- selection.index(ID = 13, pmat[c(1,3),c(1,3)], gmat[c(1,3),c(1,3)], wmat[c(1,3),1])* for more detail about question follow stack overflow link: https://stackoverflow.com/questions/66734928/how-to-solve-this-through-loop *"Healthy soil, Healthy life."* *"A war based on Satyagraha is always of two kinds. One is the war we wage against injustice, and the other we fight our won weaknesses."* - *Sardar Patel* *"You have to dream before your dreams can come true."* - *A. P. J.* *Abdul Kalam* *"Think before you print and save a tree."* *ZANKRUT GOYANI* *B.Sc. (Hons.) Agriculture* [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.