I have three variables which I want to call from a vector containing variable names produced by concatenating the string "variable." with the suffix "ONE", "TWO" and "THREE", as per code below:
variable.ONE <- 1
variable.TWO <- 2
variable.THREE <- 3
j <- c("ONE","TWO","THREE")
variables <- paste0("variable.",j)
"Variables" prints:
variables
[1] "variable.ONE" "variable.TWO" "variable.THREE"
I am looking for a way to return the values of all three variables contained in the vector "variables", hence:
[1] 1 2 3
However, calling the variables contained in "variables" does not work as intended:
get(variables) produces:
[1] 1
eval(noquote(variables))) produces:
[1] variable.ONE variable.TWO variable.THREE
eval(as.name(variables))) produces:
[1] 1
These attempts are only three of many, none of which brought me to the desired - and simple - output of:
[1] 1 2 3
Therefore, I would greatly appreciate any help you may be able to offer!
Thanks in advance!