summary

Print summary of table or categorical array

Syntax

Description

example

summary(T) prints a summary of the table, T. The table summary displays the table description from T.Properties.Description followed by a summary of the table variables.

example

summary(A) prints a summary of the categorical array, A.

  • If A is a vector, then sumamry(A) displays the category names along with the number of elements in each category (the category counts). Furthermore, the summary contains the number of elements that are undefined.

  • If A is a matrix, then summary treats the columns of A as vectors and displays the category counts for each column of A.

  • If A is a multidimensional array, then summary acts along the first array dimension whose size does not equal 1.

example

summary(A,dim) prints the category counts of the categorical array, A, along dimension dim.

For example, you can display the counts of each row in a categorical array using counts(A,2).

Examples

expand all

Summary of Table

Create a table.

load patients
BloodPressure = [Systolic Diastolic];
T = table(Gender,Age,Smoker,BloodPressure,'RowNames',LastName);

Add descriptions and units to table T.

T.Properties.Description = 'Simulated patient data';
T.Properties.VariableUnits =  {''  'Yrs' ''  'mm Hg'};
T.Properties.VariableDescriptions{4} = 'Systolic/Diastolic';

Print a summary of table T.

format compact

summary(T)
Description:  Simulated patient data
Variables:
    Gender: 100x1 cell string
    Age: 100x1 double
        Units:  Yrs
        Values:
            min       25   
            median    39   
            max       50   
    Smoker: 100x1 logical
        Values:
            true     34      
            false    66      
    BloodPressure: 100x2 double
        Units:  mm Hg
        Description:  Systolic/Diastolic
        Values:
                      BloodPressure_1    BloodPressure_2
                      _______________    _______________
            min       109                  68           
            median    122                81.5           
            max       138                  99           

summary displays the minimum, median, and maximum values for each column of the variable BloodPressure.

Summary of Categorical Vector

Create a 1-by-5 categorical vector.

A = categorical({'plane' 'car' 'train' 'car' 'plane'})
A = 

     plane      car      train      car      plane 

A has three categories, car, plane, and train.

Print a summary of A.

summary(A)
     car      plane      train 
       2          2          1 

car appears in two elements of A, plane appears in two elements, and train appears in one element.

Since A is a row vector, summary lists the occurrences of each category horizontally.

Summary of Each Column in Categorical Array

Create a 3-by-2 categorical array, A, from a numeric array.

X = [1 3; 2 1; 3 1; 4 2];
valueset = 1:3;
catnames = {'red' 'green' 'blue'};

A = categorical(X,valueset,catnames)
A = 

     red              blue  
     green            red   
     blue             red   
     <undefined>      green 

A has three categories, red, green, and blue. The value, 4, was not included in the valueset input to the categorical function. Therefore, the corresponding element, A(4,1), does not have a corresponding category and is undefined.

Print a summary of A.

summary(A)
     red              1      2 
     green            1      1 
     blue             1      1 
     <undefined>      1      0 

red appears in one element in the first column of A and two in the second column.

green appears in one element in the first column of A and none in the second column.

blue appears in one element in the first column of A and one in the second column.

A contains only one undefined element. It occurs in the first column.

Category Counts of Each Row in Categorical Array

Create a 3-by-2 categorical array, A, from a numeric array.

A = categorical([1 3; 2 1; 3 1],1:3,{'red' 'green' 'blue'})
A = 

     red        blue 
     green      red  
     blue       red  

A has three categories, red, green, and blue.

Print a summary of A along the second dimension.

summary(A,2)
     red      green      blue 
       1          0         1 
       1          1         0 
       1          0         1 

red appears in one element in the first row of A, one in the second row, and one in the third row.

green appears in only one element. It occurs in the second row of A.

blue appears in one element in the first row of A and one in the third column.

Input Arguments

expand all

T — Input tabletable

Input table, specified as a table.

A — Categorical arrayvector | matrix | multidimensional array

Categorical array, specified as a vector, matrix, or multidimensional array.

dim — Dimension of A to operate alongpositive integer scalar

Dimension of A to operate to along, specified as a positive integer scalar. If no value is specified, the default is the first array dimension whose size does not equal 1.

Consider a two-dimensional categorical array, A:

If dim = 1, then summary(A,1) displays the category counts for each column of A.

If dim = 2, then sumary(A,2) returns the category counts of each row of A.

If dim is greater than ndims(A), thensummary(A) returns an array the same size as A for each category. summary returns 1 for elements in the corresponding category and 0 otherwise.

More About

expand all

Table Summary

The table summary displays the table description from T.Properties.Description followed by information on the variables of T.

The summary contains the following information on the variables:

  • Name: Size and Data Type — variable name from T.Properties.VariableNames, the size of the variable, and the data type of the variable.

  • Units — variable's units from T.Properties.VariableUnits.

  • Description — variable's description from T.Properties.VariableDescriptions.

  • Values — only included for numeric variables, logical variables, or categorical variables.

    • numeric variables — minimum, median, and maximum values.

    • logical variables — number of values that are true and the number of values that are false.

    • categorical variables — number of elements from each category.

Was this topic helpful?