I have several formulas in string form, read from files, like this: "0.657 + 0.343*age - 1.239 * cholesterol"
and I would like to convert each of these into a formula object to run on a data frame (ie. my.formula <- 0.657 + 0.343*age - 1.239 * cholesterol
) . How can I do that programmatically?
Use eval
and parse
example:
> cholesterol <- 2 # set some values for cholesterol and age
> age <- 3
> eval(parse(text="0.657 + 0.343*age - 1.239 * cholesterol"))
[1] -0.792
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With