'Is it possible to make a character and return what that character's value in the the global environment?
I am not sure if this is possible but I would like to return the global environment value of each element in a vector that was generated using sprintf.
v1 <- 'value 1'
v2 <- 'value 2'
v3 <- 'value 3'
obs <- noquote(sprintf('%s%d', 'v', 1:3))
obs
obs returns:
[1] v1 v2 v3
But I would like it to return the value of c(v1, v2, v3):
[1] "value 1" "value 2" "value 3"
Solution 1:[1]
mget(obs)
# $v1
# [1] "value 1"
# $v2
# [1] "value 2"
# $v3
# [1] "value 3"
unlist(mget(obs))
# v1 v2 v3
# "value 1" "value 2" "value 3"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | r2evans |
