Frequency Tables

In what follows, it is assumed that data are available as a data.frame; in other words, it assumed that there columns of data with "names" attached. Some other classes may also work.

Frequency Tables

As yet, I have not found a way to create a simple frequency table (possibly with absolute, relative and cumulative frequencies) in a user friendly way. I'm afraid that's the way R is!

For a table containing all three elements mentioned in the previous paragraph try the following series of commands:

tab1a <- table(name-of-file$variablename)
tab1r <- prop.table(tab1a)
tab1c <- cumsum(tab1r)
tab1full <- cbind(tab1a, tab1r,tab1c)

Note how each line builds on its predecessor: The relative frequencies are built from the table of absolute frequencies, and the cumulative frequencies from the relative frequencies. The final line binds all three objects together into a single object that resembles the frequency table we've grown accustomed to. – You can write tab1r <- prop.table(tab1a) * 100 to obtain percentages instead of proportions.

Elementary Plots

Plots can be created from a table with, e.g.,

plot(tab1a)

or with

barplot(tab1a)

The graphs are shown in the entry about charts for discrete data

© W. Ludwig-Mayerhofer, IGRW | Last update: 21 Jun 2025