Based on calculations I have created a list, which contains 10 lists named by year (e.g. y2000 for 2000) and each year-list contains, in its turn, two result matrices (A and B).
For analysis purpose I would like to create a variable year and matrix, assign values to them.
For instance: year = 2000
and matrix = A
Based on this variables I would like to return a desired matrix.
I tried to use get()
with paste0()
and different ways of list-notation, however none of the tries returned the result.
If I run
Data$y2000$A
- the matrix is being returned, but
get(paste0("Data[[y",year,"]][[",matrix,"]]))
returns an error
object 'y2000' not found
also I have tried to use brackets and backticks, but it still returns the same error.
get(paste0("Data[[`y",year,"`]][[`",matrix,"`]]))
How one can return an object via a variable?