Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get value when a variable name is passed as a string

Tags:

i write this code in R

paste("a","b","c")  

which returns the value "abc"

Variable abc has a value of 5(say) how do i get "abc" to give me the value 5 is there any function like as.value(paste("a","b","c")) which will give me the answer 5? I am making my doubt sound simple and this is exactly what i want. So please help me. Thanks in advance

like image 423
Ruser Avatar asked May 03 '12 10:05

Ruser


People also ask

How do you get the value of a string variable in Python?

Int value of a string can be obtained by using inbuilt function in python called as int() . Here we can pass string as argument to this function which returns int value of a string.

How do you find the value of a variable name?

Method 2: Using $$ Operator: The $$var_name is known as reference variable where $var_name is a normal variable. The $$var_name used to refer to the variable with the name as value of the variable $var_name. Example: This example uses $$ operator to get the variable name as a string. print ( $name );

How do you convert a variable to a string?

We can convert numbers to strings through using the str() method. We'll pass either a number or a variable into the parentheses of the method and then that numeric value will be converted into a string value. The quotes around the number 12 signify that the number is no longer an integer but is now a string value.

How do you check if a variable equals a string?

To check if a variable contains a value that is a string, use the isinstance built-in function. The isinstance function takes two arguments. The first is your variable. The second is the type you want to check for.


1 Answers

paste("a","b","c") gives "a b c" not "abc"

Anyway, I think you are looking for get():

> abc <- 5 > get("abc") [1] 5 
like image 133
Sacha Epskamp Avatar answered Sep 18 '22 18:09

Sacha Epskamp