Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

variables

r

r-faq

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?

like image 620
Zhang18 Avatar asked Oct 19 '10 19:10

Zhang18


People also ask

What is a value that can be stored in an string?

A string is a type of value that can be stored in a variable. A string is made up of characters, and can include letters, words, phrases, or symbols. Definition: Strings hold groups of characters, like a word or a phrase.

What value is stored in the variable name?

The information "stored" in a variable, is the last piece of information assigned to that variable name. After assigning into a variable, all previous information is lost.


1 Answers

You provided the answer in your question. Try get.

> get(x) [1] 1 2 3 
like image 194
Joshua Ulrich Avatar answered Oct 08 '22 11:10

Joshua Ulrich