r - calculate fat free mass and apply the function to data set -
i have dataset looks this:
id sex weight bmi 1 2 65 25 1 2 65 25 1 2 65 25 2 1 70 30 2 1 70 30 2 1 70 30 2 1 70 30 3 2 50 18 3 2 50 18 4 1 85 20 4 1 85 20
i want calculate fat free mass (ffm) , attach value in new column in dataset each individual. these functions calculate ffm males , females:
for males (sex=1):
ffmcalmale <- function (weight, bmi) { ffm = 9270*weight/(6680+216*bmi) }
and females (sex=2):
ffmcalfemale <- function(weight, bmi) { ffm = 9270*weight/(8780+244*bmi)
}
i want modify function check sex (1, male or 2 female) calculation ffm based on , apply function each individual. please help?
thanks in advance!
you utilize ifelse
data$ffm <- ifelse(data$sex==1, ffmcalmale(data$weight, data$bmi), ffmcalfemale(data$weight, data$bmi))
r data.frame
No comments:
Post a Comment