Greetings of the day,
Thank you for your response, Sir.
The full problem statement is given below:
In our case, I'm taking 4 traits.
library(arrangements)
a<- combinations(4,2) # gives 6 pairwise combinations
class(a) # it's a "matrix" "array"
now hypothetical data of three matrix for further calculation:
pmat<- matrix(1:16, nrow = 4)
gmat<- matrix(17:32, nrow = 4)
wmat<- matrix(1:4, nrow = 4)
My custom function for further calculations:
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))
}
Now I want to store this data into a list for further calculation:
sc<- list()
sc[[1]]<- selection.index(ID = 12, phen_mat = pmat[c(1,2),c(1,2)], gen_mat =
gmat[c(1,2),c(1,2)], weight_mat = wmat[c(1,2),1])
sc[[2]]<- selection.index(ID = 13, phen_mat = pmat[c(1,3),c(1,3)], gen_mat =
gmat[c(1,3),c(1,3)], weight_mat = wmat[c(1,3),1])
sc[[3]]<- selection.index(ID = 14, phen_mat = pmat[c(1,4),c(1,4)], gen_mat =
gmat[c(1,4),c(1,4)], weight_mat = wmat[c(1,4),1])
sc[[4]]<- selection.index(ID = 23, phen_mat = pmat[c(2,3),c(2,3)], gen_mat =
gmat[c(2,3),c(2,3)], weight_mat = wmat[c(2,3),1])
sc[[5]]<- selection.index(ID = 24, phen_mat = pmat[c(2,4),c(2,4)], gen_mat =
gmat[c(2,4),c(2,4)], weight_mat = wmat[c(2,4),1])
sc[[6]]<- selection.index(ID = 34, phen_mat = pmat[c(3,4),c(3,4)], gen_mat =
gmat[c(3,4),c(3,4)], weight_mat = wmat[c(3,4),1])
above list code is monotonous and time consuming for large data combination
cycles like (7,2) = 21 combinations, (10,2) = 45 combinations. So I want to use
the matrix a's each row as a vector in the selection.index function and result
stores in a list.
I hope now you will understand the full problem. I have checked the
selection.index which has no issues and works well.
Thank you.