简体   繁体   中英

How to transform a string to a “formula” which allows to use binary operators

I have the following string in R:

data<-"-1/(1 - Ft)"  # Ft is a variable provided by the user

How can I transform this string in order to be able to operate with it?

This is my desired operation

data / 5

which means: (-1/(1 - Ft))/5

Do you know how can I achieve this?

It would be eval(parse (assuming 'Ft' is an object created in the global env)

Ft <- 4
eval(parse(text = data))/5
#[1] 0.06666667

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