0

Example: There is a matrix of data called VE There is a vector of string where the first element is the string VE. I need to indirectly call the string and be able to access data. For example if I need the 6th column of matrix VE then I want to do:

Vector[1][,6]

Essentially I need R to start reading those string as if they are the matrix names that are already in this page. I need this syntax to be dynamic because I am putting it in a loop.

  • As far as I know R doesn't have pointers. So you have to use some workaround, like lists. But it would work much better if R have pointers. – Manoel Galdino Feb 27 '11 at 14:47

1 Answers1

2

I think you are looking for get():

VE <- matrix(0,10,10)
vec <- c("VE","foo","bar")
get(vec[1])[,6]

Edit:

This requires a global object called VE though, for automating it is probably better to keep the matrices (I assume there are more?) in a list, then you can just index:

matrixlist <- list(VE = matrix(0,10,10))
vec <- c("VE","foo","bar")
matrixlist[[vec[1]]][,6]
Sacha Epskamp
  • 46,463
  • 20
  • 113
  • 131