Reputation: 435
I would like to refer to values saved in two variables by a key variable, f.e.
Variable "key": first, second, third
Variable "color": green, yellow, red
Variable "furniture": table, chair, door
So:
first > green + table
second > yellow + chair
third > red + door
If variable key is now "first", I would like get the values "green" from color and "table" from furniture.
Thank you!
Upvotes: 0
Views: 37
Reputation: 39717
You can name the vector to access it by name.
color <- c(first="green", second="yellow", third="red")
furniture <- c(first="table", second="chair", third="door")
key <- "first"
color[key]
# first
#"green"
furniture[key]
# first
#"table"
Upvotes: 1