I need to calculate a reference equation for an examination we conducted in a study cohort.
The equation used depends on whether the participant is male or female.
For male participants the equation is:
6MWD = (7.57 × heightcm) − (5.02 × age) − (1.76 × weightkg) − 309 m
and for female participants it is:
6MWD = (2.11 × heightcm) − (2.29 × weightkg) − (5.78 × age) + 667 m
I tried adding a column to my table with the solution of the equation by writing:
SMWD$RefEq <- ifelse(SMWD$gender =="male", (7.57*'Height')-(5.02*'Age')-(1.76*'Weight')-309, (2.11*'Height')-(2.29*'Weight')-(5.78*'Age')+667)
Yet, i get an "unused argument" error.
How do I solve this problem or is there any better way to calculate the reference equation?
in baseR, unless you attach or use a construct like within, you have to specificy where the variable you want comes from, like you did with SMWD$gender, but unlike when you referened 'Height' which to R just seems like some text that says Height in it. So either you rewrite your statement to
SMWD$RefEq <- ifelse(SMWD$gender =="male", (7.57*SMWD$Height) etc.
or switch to a dplyr syntax ( install.packages("dplyr") as a one time first step)
inside of a dplyr mutate, its generally clear where the variable mentioned should come from ( the data.frame that mutate is operating on)
More info here: https://r4ds.had.co.nz/