Working with frequencies in RLearn everything about frequencies

The "basic R statistics" tutorial works with the women dataset. This frequencies tutorial will work with the discoveries dataset because every meting on it self is a frequency.

Absolute frequentie in R

The absolute frequentie shows how many times a meting will occur. The first row will show the data and the second row shows the frequency. Note: Do not forget to load the discoveries dataset.

  • table(discoveries)   # Loads the frequentie table from the discoveries dataset

Mode in R

There is no easy function to calculate the mode in R so we will use a combination of functions to calculate it.

  • sort(table(discoveries))   # Sorts from low to high
  • sort(table(discoveries), TRUE)   # Sorts from high to low with the TRUE parameter
  • names(sort(table(discoveries),TRUE))[1]   # Only show the name from the first element.

You may want to write your own function to calculate the mode in R:

  • modus = function (x) { as.numeric(names(sort(table(x),TRUE))[1]) }   # Function to calculate the modus. Note that this function will not work for all data

Relative frequency in R

Showing the relative frequency in R is easy. Note that if you multiply this number by 100 you will get the percentage:

  • table(discoveries) / length(discoveries)   # Calculates the relative frequency

Cumulative frequencies in R

There is the cumulative absolute frequency and the cumulative relative frequency. Calculating them is easy:

  • cumsum(table(discoveries))   # Gives the cumulative absolute frequency
  • cumsum(table(discoveries) / length(discoveries))   # Gives the cumulative relative frequency

Frequency distributions in R

For frequency distributions in R you will have to set your data to a table in order to calculate the frequencies. How to do this in R:

  • normdata = rnorm(10000)   # Generates 10000 random numbers. This will be explained in the following tutorials
  • cut(normdata, breaks = -6:6)   # Cut puts every number in the correct category. Breaks makes the categories.
  • table(cut(normdata, breaks = -6:6))   # Places the data in a table