1
Split the patient weights by both gender and status as a smoker and calculate the mean weights.
G = findgroups(Gender,Smoker);
meanWeight = splitapply(@mean,Weight,G)
meanWeight = 4×1
130.3250
130.9231
180.0385
181.1429
The unique combinations across Gender and Smoker identify four groups of patients: female
nonsmokers, female smokers, male nonsmokers, and male smokers. Summarize the four groups and
their mean weights in a table.
[G,gender,smoker] = findgroups(Gender,Smoker);
T = table(gender,smoker,meanWeight)
T=4×3 table
gender
smoker
meanWeight
______
______
__________
Female
false
130.32
Female
true
130.92
Male
false
180.04
Male
true
181.14
T.gender contains categorical values, and T.smoker contains logical values. The data types of these
table variables match the data types of Gender and Smoker respectively.
Calculate body mass index (BMI) for the four groups of patients. Define a function that takes Height
and Weight as its two input arguments, and that calculates BMI.
meanBMIfcn = @(h,w)mean((w ./ (h.^2)) * 703);
BMI = splitapply(meanBMIfcn,Height,Weight,G)
BMI = 4×1
21.6721
21.6686
26.5775
26.4584
Group Patients Based on Self-Reports
Calculate the fraction of patients who report their health as either Poor or Fair. First, use
splitapply to count the number of patients in each group: female nonsmokers, female smokers,
male nonsmokers, and male smokers. Then, count only those patients who report their health as
either Poor or Fair, using logical indexing on S and G. From these two sets of counts, calculate the
fraction for each group.
9 Tables
9-50
Précédent

- 394/1450

Suivant