An R Introduction to Statistics

Frequency Distribution of Qualitative Data

The frequency distribution of a data variable is a summary of the data occurrence in a collection of non-overlapping categories.

Example

In the data set painters, the frequency distribution of the School variable is a summary of the number of painters in each school.

Problem

Find the frequency distribution of the painter schools in the data set painters.

Solution

We apply the table function to compute the frequency distribution of the School variable.

> library(MASS)                 # load the MASS package 
> school = painters$School      # the painter schools 
> school.freq = table(school)   # apply the table function

Answer

The frequency distribution of the schools is:

> school.freq 
school 
 A  B  C  D  E  F  G  H 
10  6  6 10  7  4  7  4

Enhanced Solution

We apply the cbind function to print the result in column format.

> cbind(school.freq) 
  school.freq 
A          10 
B           6 
C           6 
D          10 
E           7 
F           4 
G           7 
H           4

Exercise

  1. Find the frequency distribution of the composition scores in painters.
  2. Find programmatically the school that has the most painters.