# Relative Frequency Distribution of Qualitative Data

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

The relationship of frequency and relative frequency is:

#### Example

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

#### Problem

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

#### Solution

We first 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

Then we find the sample size of painters with the nrow function, and divide the frequency distribution with it. Therefore the relative frequency distribution is:

> school.relfreq = school.freq / nrow(painters)

The relative frequency distribution of the schools is:

> school.relfreq
school
A        B        C        D        E        F
0.185185 0.111111 0.111111 0.185185 0.129630 0.074074
G        H
0.129630 0.074074

#### Enhanced Solution

We can print with fewer digits and make it more readable by setting the digits option.

> old = options(digits=1)
> school.relfreq
school
A    B    C    D    E    F    G    H
0.19 0.11 0.11 0.19 0.13 0.07 0.13 0.07
> options(old)

In addition, we can apply the cbind function to print the result in column format.

> old = options(digits=1)
> cbind(school.relfreq)
school.relfreq
A           0.19
B           0.11
C           0.11
D           0.19
E           0.13
F           0.07
G           0.13
H           0.07
> options(old)    # restore the old option

#### Exercise

Find the relative frequency distribution of the composition scores in painters.