JAMES 'male' 78 75 77 76.667
WATSON 'female' 91 94 92 92.333
BROOKS 'female' 86 83 85 84.667
KELLY 'male' 79 76 82 79
Alternatively, you can use the variable names, T{:,{'Test1','Test2','Test3'}} or
the variable indices, T{:,2:4} to select the subset of data.
Compute Statistics Using Grouping Variable
Compute the mean and maximum of TestAvg by gender of the students.
varfun(@mean,T,'InputVariables','TestAvg',...
'GroupingVariables','Gender')
ans=2×3 table
Gender GroupCount mean_TestAvg
'female' 5 87.067
'male' 5 83.4
Replace Data Values
The maximum score for each test is 100. Use curly braces to extract the data from the
table and convert the test scores to a 25 point scale.
T{:,2:end} = T{:,2:end}*25/100
T=10×5 table
Gender Test1 Test2 Test3 TestAvg
HOWARD 'male' 22.5 21.75 23.25 22.5
WARD 'male' 21.75 21.25 20.75 21.25
TORRES 'male' 21.5 21.25 22 21.583
PETERSON 'female' 18.75 20 18 18.917
GRAY 'female' 22.25 21.5 21.75 21.833
RAMIREZ 'female' 24 23 24.5 23.833
JAMES 'male' 19.5 18.75 19.25 19.167
WATSON 'female' 22.75 23.5 23 23.083
BROOKS 'female' 21.5 20.75 21.25 21.167
KELLY 'male' 19.75 19 20.5 19.75
Calculations on Tables