
----- Original Message ----- 
From: Robin Gruna 
To: R-help@lists.R-project.org 
Sent: Sunday, June 20, 2004 5:42 PM
Subject: Evaluating strings as variables


Hello,
I have the following problem: I have a list as follows,

> values <- list(red = 1, yellow = 2, blue = 3)

> values
$red
[1] 1

$yellow
[1] 2

$blue
[1] 3

There is also a vector containing the diffrent "colors" as character strings:

> colors <- c("red", "red", "blue", "yellow", "red", "blue")
> colors
[1] "red"    "red"    "blue"   "yellow" "red"    "blue"  

Now i can attach the list values to R:

> attach(values)
> red
[1] 1

etc...

Now to my problem: How can I make R in a simple way to evaluate the strings "red", "blue" etc. as variables, returning their numeric values ?
As result I want to get a vector containing the values of the colors like this one:

> values.colors
[1] 1 1 3 2 1 3

Thanks a lot,
greetings Robin











	[[alternative HTML version deleted]]


