# Concept of performing a t-test while controlling/adjusting for one or more variables? [duplicate]

E.g.: Say I have a hypothetical data set, with the following variables sex, age, smoker, weight, height, bmi, smoking_duration, max_oxygen_uptake. Let us say I want to test if smokers have a higher max_oxygen_uptake, than non-smokers?

Then in R I would write: t.test(subset(myData,myData$smoker==0)$max_oxygen_uptake,subset(myData,myData$smoker==1)$max_oxygen_uptake)

But max_oxygen_uptake will likely also depend on e.g. age, bmi and smoking_duration. Maybe also sex. Therefore I am looking for something along the lines of: t.test(var_a,var_b,adjust=c(var_c,var_d,var_e)).

Questions:

1. How do I perform a t-test, while controlling/adjusting for other variables?

2. How do I decide which variables should be controlled/adjusted for?

I know it has something to do with lm(), but I am having conceptual problems in connecting the t-test to creating a linear model?