简体   繁体   English

求解r中x的不同值的方程式

[英]Solve equation for different values of x in r

I am trying to solve an equation for different values of x={0,1,....,53}. 我正在尝试为x = {0,1,....,53}的不同值求解方程。

The equation is: 等式是:

y = -0.5*mean(sp_2$IMR) - 0.1*mean(sp_2$rev) - 0.04*x + 1.2*x*mean(sp_2$ebrd)

Note that IMR, rev and ebrd are vectors of 540 observations in the dataframe sp_2. 请注意,IMR,rev和ebrd是数据帧sp_2中540个观测值的向量。

The result after solving this equations for all 54 x values should be an array of 54 y values. 解决所有54个x值的方程后,结果应为54个y值的数组。 Which function should I use to achieve this and what is the complete syntax? 我应该使用哪个函数来实现这一目标,完整的语法是什么?

Did you try using seq or the : notation: 您是否尝试使用seq:表示法:

x <- 0:53
y <- -0.5 * mean(sp_2$IMR) - 0.1 * mean(sp_2$rev) - 0.04 * x + 1.2 * x * mean(sp_2$ebrd)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM