Converting an equation into R code -
i have long expression want convert r code. here example showing expression looks like/how written:
(a exp(-a t) t^4)/(24 (a-b) (a-c) (a-d))
in order understandable r, multiplication sign *
should added between variables, brackets etc. there way automatically rather inserting manually? expression should this:
(a *exp(-a*t) *t^4)/(24* (a-b)* (a-c)* (a-d))
if input of form shown sufficient replace each space * using gsub
this:
expr <- "(a exp(-a t) t^4)/(24 (a-b) (a-c) (a-d))" gsub(" +", "*", expr) ## [1] "(a*exp(-a*t)*t^4)/(24*(a-b)*(a-c)*(a-d))"
Comments
Post a Comment