I have the name of a matrix as string and would like to assign to a column of that matrix.
A <- matrix(1:4,2)
v <- 10:11
name <- "A"
get(name)[,2] <- v
This does not work because the LHS is just a value (i.e. a vector) and has lost the meaning of "the second column of A".
eval(parse(text=paste0(name,'[,2]<- v')))
This does the job, but a lot of people discourage the use of such a structure. What is the recommended way to go about this?
EDIT: Most comments on similar problems I have found discourage the use of object names that can only be passed as strings and instead promote the use of lists, i.e.
l <- list(A=matrix(1:4,2))
v <- 10:11
name <- "A"
l[[name]][,2] <- v
but this does not really answer my question.