R内部的呼叫和评估功能

Nar*_*ni -1 eval r call

我正在编写一个函数,我想提供一个变量,其中包含要在函数内部进行求值的条件.例如,我有一个小时变量,包含0,3,6,9,18,3,6,9,18,0,18等值...我想选择小时变量匹配为0,6的索引这个0,6可能会根据其他一些参数而改变.基本上它们并不总是固定的.所以我传递一个变量g1 = call("which", (hourval==0 | hourval == 6)).我希望在程序中评估此语句.因此我使用该声明x1 = eval(g1).显然,当我传递变量时g1,不会生成那个时间的小时变量,而是在eval(g1)语句之前生成它.我收到错误,hourval找不到对象.有没有其他方法可以解决这个问题.

在此先感谢,任何帮助表示赞赏.

Narayani Barve

42-*_*42- 7

这是你想要的吗?

> hourval <- c(0, 3, 6, 9, 18, 3, 6, 9, 18, 0, 3, 18)
> test <- c(0,6)
> which(hourval %in% test)
[1]  1  3  7 10
Run Code Online (Sandbox Code Playgroud)

我花了一段时间才用这个搜索策略找到它

library(fortunes)
fortune("parse")
Run Code Online (Sandbox Code Playgroud)

但最终得到了我记得的那个:

> fortune("parse")

If the answer is parse() you should usually rethink the question.
   -- Thomas Lumley
      R-help (February 2005)
Run Code Online (Sandbox Code Playgroud)

我的一部分困难在于我记得引用为"eval(解析(").