5

I have a function, such as Q = 4000-50P, written in R as q1 <- function(p_)pmax(0,4000-50*p_)

and I want to rewrite the equation in terms of P, to get P = 80-(1/50)*Q, written in R as p1 <- function(q1_)pmax(0,80-(1/50)*q1_)

Is there a way for R to solve a function/equation for another variable? I want to tell R to solve the first equation in terms of p_. I can't seem to find any answers online. Thanks in advance!

Saurabh Chauhan
  • 3,161
  • 2
  • 19
  • 46
D. Li
  • 123
  • 6
  • 2
    Are you looking for manipulation of the formula of the function or for a numeric solution? – jogo Aug 01 '18 at 07:30
  • 1
    If you want a numeric solution, the question is duplicated, see [here](https://stackoverflow.com/questions/10081479/solving-for-the-inverse-of-a-function-in-r). – Juan Antonio Roldán Díaz Aug 01 '18 at 07:50
  • I'm looking for a manipulation of the formula of the function, not a numeric solution – D. Li Aug 01 '18 at 11:24
  • Thanks Juan! The link works perfectly – D. Li Aug 01 '18 at 12:01
  • Eventually you can use the package `formula.tools` https://cran.r-project.org/web/packages/formula.tools/formula.tools.pdf There is a function `invert()` – jogo Aug 02 '18 at 11:48

0 Answers0