访问变量值,其中变量的名称存储在字符串中

访问变量值,其中变量的名称存储在字符串中

问题描述:

针对其他语言提出了类似的问题:Csqljava

Similar questions have been raised for other languages: C, sql, java, etc.

但我试图在 R 中做到这一点.

But I'm trying to do this in R.

我有:

ret_series <- c(1, 2, 3)
x <- "ret_series"

如何通过在 x 上调用一些函数/操作来获得 (1, 2, 3),而不直接提到 ret_series?

How do I get (1, 2, 3) by calling some function / manipulation on x, without direct mentioning of ret_series?

您在问题中提供了答案.尝试 get.

You provided the answer in your question. Try get.

> get(x)
[1] 1 2 3