Search code examples
rvariablesr-faq

Access variable value where the name of variable is stored in a string


Similar questions have been raised for other languages: C, sql, java, etc.

But I'm trying to do this in R.

I have:

ret_series <- c(1, 2, 3)
x <- "ret_series"

How do I get (1, 2, 3) by calling some function / manipulation on x, without direct mentioning of ret_series?


Solution

  • You provided the answer in your question. Try get.

    > get(x)
    [1] 1 2 3