I might have factored the gender. I'm not sure it would in any way be quicker. But might be to some extent easier to develop variations of. And is sort of what factors should be doing...
# make dummy data gender <- c("Male", "Female", "Male", "Female") WC <- c(70,60,75,65) TG <- c(0.9, 1.1, 1.2, 1.0) myDf <- data.frame( gender, WC, TG ) # label a factor myDf$GF <- factor(myDf$gender, labels= c("Male"=65, "Female"=58)) # do the maths myDf$LAP <- (myDf$WC - as.numeric(myDf$GF))* myDf$TG #show results head(myDf) gender WC TG GF LAP 1 Male 70 0.9 58 61.2 2 Female 60 1.1 65 64.9 3 Male 75 1.2 58 87.6 4 Female 65 1.0 65 64.0 (Reality: I'd have probably used case_when in tidy to create a new numeric column) The equation to > calculate LAP is different for male and females. I am giving both equations > below. > > LAP for male = (WC-65)*TG > LAP for female = (WC-58)*TG > > My question is 'how can I calculate the LAP and create a single new column? > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.