Let’s say I have a few columns:
- life stage (levels: adult, juvenile, larva)
- Length of exposure (numeric)
- life span (numeric)
- age at maturity (numeric)
- larval duration (numeric)
- dtm (numeric)
I want to calculate some metrics using these in a new column called “proportion.life.duration”. BUT how I calculate (which variables to use) depends on what life stage.
So if life stage == “adult” then I want it to calculate the value in the new “prop.life.duration” column as “length of exposure/ (life span - age at maturity)“.
But if juvenile, I want to calculate using "length of exposure / dtm"; if larvae, I want to calculate as "length of exposure / larval duration"
HOW DO I DO THAT? in R
I thought maybe if..else statements with mutate() but havent figured out how to do that with three levels (adult, juvenile, and larva) AND using different columns to calculate for each.