简体   繁体   中英

Solve equation for different values of x in r

I am trying to solve an equation for different values of 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.

The result after solving this equations for all 54 x values should be an array of 54 y values. Which function should I use to achieve this and what is the complete syntax?

Did you try using seq or the : notation:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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