tabulate
Calculate a frequency table.
tabulate (x)
displays a frequency table of the data in the vector
x. For each unique value in x, the tabulate function shows the
number of instances and percentage of that value in x.
table = tabulate (x)
returns the frequency table,
table, as a numeric matrix when x is numeric and as a cell array
otherwise. When an output argument is requested, tabulate
does not
print the frequency table in the command window.
If x is numeric, any missing values (NaNs
) are ignored.
If all the elements of x are positive integers, then the frequency
table includes 0 counts for the integers between 1 and max (x)
that do not appear in x.
See also: bar, pareto
Source Code: tabulate
## Generate a frequency table for a vector of data in a cell array load patients ## Display the first seven entries of the Gender variable gender = Gender(1:7) ## Compute the equency table that shows the number and ## percentage of Male and Female patients tabulate (Gender) gender = { [1,1] = Male [2,1] = Male [3,1] = Female [4,1] = Female [5,1] = Female [6,1] = Female [7,1] = Female } Value Count Percent Male 47 47.00% Female 53 53.00% |
## Create a frequency table for a vector of positive integers load patients ## Display the first seven entries of the Gender variable height = Height(1:7) ## Create a frequency table that shows, in its second and third columns, ## the number and percentage of patients with a particular height. table = tabulate (Height); ## Display the first and last seven entries of the frequency table first = table(1:7,:) last = table(end-6:end,:) height = 71 69 64 67 64 68 64 first = 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 last = 66 15 15 67 6 6 68 15 15 69 8 8 70 11 11 71 10 10 72 4 4 |
## Create a frequency table from a character array load carsmall ## Tabulate the data in the Origin variable, which shows the ## country of origin of each car in the data set tabulate (Origin) Value Count Percent USA 69 69.00% France 4 4.00% Japan 15 15.00% Germany 9 9.00% Sweden 2 2.00% Italy 1 1.00% |
## Create a frequency table from a numeric vector with NaN values load carsmall ## The carsmall dataset contains measurements of 100 cars total_cars = length (MPG) ## For six cars, the MPG value is missing missingMPG = length (MPG(isnan (MPG))) ## Create a frequency table using MPG tabulate (MPG) table = tabulate (MPG); ## Only 94 cars were used valid_cars = sum (table(:,2)) total_cars = 100 missingMPG = 6 Value Count Percent 18 4 4.26% 15 5 5.32% 16 2 2.13% 17 1 1.06% 14 5 5.32% 24 4 4.26% 22 4 4.26% 21 2 2.13% 27 6 6.38% 26 4 4.26% 25 5 5.32% 10 2 2.13% 11 1 1.06% 9 1 1.06% 28 4 4.26% 17.5 2 2.13% 15.5 1 1.06% 14.5 1 1.06% 22.5 1 1.06% 29 3 3.19% 24.5 1 1.06% 33 1 1.06% 20 2 2.13% 18.5 1 1.06% 29.5 1 1.06% 32 4 4.26% 26.5 1 1.06% 13 4 4.26% 19 2 2.13% 16.5 2 2.13% 34 2 2.13% 31 3 3.19% 23 1 1.06% 36 5 5.32% 37 1 1.06% 38 4 4.26% 44 1 1.06% valid_cars = 94 |