在R中包含表达式调用中的变量 [英] Including variables in expression call in R

查看:136
本文介绍了在R中包含表达式调用中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在R中使用表达式是否可以包含变量。



例如我想做这样的事情:

  par(mfrow = c(2,3))
for(i在1:6)
{
plot(x,p1-i * p2,main = expression(Phi [1] - i * Phi [2]))
}

但是这不起作用,因为它打印Φ 1 - i&Phi 2 (即它不代替 i 1,2,... 6

解决方案

使用替代:

 > ;替代(Phi [1]  -  i * Phi [2],list(i = i))
Phi [1] - 3 * Phi [2]
pre>

I was wondering if it were possible to include variables when using expression in R.

For instance I would like to do something like this:

par(mfrow=c(2,3))
for (i in 1:6)
    {
    plot(x, p1-i*p2, main=expression(Phi[1] - i * Phi[2]))
    }

But this does not work, as it prints Φ1 - iΦ2 (i.e. it does not substitute i with 1, 2, ... 6

解决方案

Use substitute:

> substitute(Phi[1] - i* Phi[2], list(i = i))
Phi[1] - 3 * Phi[2]

这篇关于在R中包含表达式调用中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆