I have the following problem: I have a huge list of matrices with unique names that share the same dimension. I calculate some values that I now want to assign to a certain matrix indice, e.g. [3,4]. Because I have so many matrices I created a list with the names that those matrices shall have and then I used assign()
to create all those matrices (empty). I would now like to call single matrices with its variable name to assign different values to certain matrix entries. I only know the commands assign() and eval(parse())
, but didn't manage to get it working. I tried several things without success:
assign(x=MatrixNameList[i][3,4],value=z)
assign(x=MatrixNameList[i],value=z)[3,4]
eval(parse(text=MatrixNameList[i]))[3,4]<-z
assign(x=eval(parse(text=MatrixNameList[i]))[3,4] ,value=z)
So I am wondering if there is a possibility for what I want to do. The structure of my code is a simple loop:
Matrix1 <- Matrix2 <- matrix(nrow=3,ncol=4)
MatrixNameList <- c('Matrix1', 'Matrix2')
for (i in 1:length(MatrixNameList)){
z <- calculatedValue <- 4 # different for the single matrices
assign... ?
eval(parse... ?
}
I hope I was able to clearly point out my problem. Thanks in advance, Eric