Does anyone know of a way to use an equation that is given as a string as an actual equation or formula in R?
I have a database with allometric equations (that you can use to calculate/estimate biomass of trees), together with information on locations and species for which they were developed. I also have another large observed dataset with observed species; so I loop over all these species and their location to find the allometric equation for each, and the equations can be very different [this is just to indicate that this is not a once-off exercise so I cannot use a very specific approach]. I then want to use my observed dataset (with things like diameter and height of the trees) to calculate biomass - but I don't know how to actually use the expression that is in the allometric equation database. See below a very short example.
X Z Equation Genus Species
DBH NA 0.1731*X^(2.0296) All All
DBH NA 0.1027*X^(2.4798) All All
DBH H (-4.58643+1.90532*log10(X)+1.0646*log10(Z)) Tectona grandis
DBH H (-4.58643+1.90532*log10(X)+1.0646*log10(Z)) Tectona grandis
DBH NA 0.000189*X^(2.262) Dalbergia melanoxylon
DBH H 0.0763*X^(2.2046)*Z^(0.4918) All All
So let's say I have Tectona grandis in my observed data, I want to be able to extract -4.58643+1.90532*log10(X)+1.0646*log10(Z)
and use it with my observed X
(diameter) and Z
(height).
I need some sort of "generic" solution since I am dealing with a lot of species and a lot of different equations. I know how to select the actual equation, but then I have it as a factor - how do I operationalize it? Can I?