Home Back

How to Calculate Relative Frequency in R

R Code for Relative Frequency Table:

\[ rel\_freq <- table(data) / sum(table(data)) \]

e.g., 1,2,2,3,3,3,4

Unit Converter ▲

Unit Converter ▼

From: To:

1. What is Relative Frequency?

Relative frequency is the ratio of the number of times a particular value occurs in a dataset to the total number of observations. It represents the proportion or percentage of each category in the data.

2. How to Calculate Relative Frequency in R

The standard R code for calculating relative frequency is:

\[ rel\_freq <- table(data) / sum(table(data)) \]

Where:

3. Understanding the R Code

Step-by-step breakdown:

  1. table(data) creates a contingency table showing frequency counts
  2. sum(table(data)) sums all frequency counts to get total observations
  3. The division operation converts absolute frequencies to relative frequencies
  4. The result is stored in rel_freq vector

Example Output: For data = c(1,2,2,3,3,3), the relative frequency table would show:

4. Practical Applications

Data Analysis: Relative frequency is fundamental in descriptive statistics for understanding data distribution, identifying patterns, and preparing data for visualization.

Research: Used in survey analysis, market research, and scientific studies to understand proportions and percentages within datasets.

5. Frequently Asked Questions (FAQ)

Q1: What's the difference between frequency and relative frequency?
A: Frequency is the actual count of occurrences, while relative frequency is the proportion (frequency divided by total observations).

Q2: Can I calculate relative frequency for categorical data?
A: Yes, the table() function works with both numerical and categorical data in R.

Q3: How do I convert relative frequency to percentage?
A: Multiply the relative frequency by 100: percentage <- rel_freq * 100

Q4: What if my data has missing values?
A: Use table(data, useNA = "ifany") to include NA values in the frequency count.

Q5: Are there alternative methods in R?
A: Yes, you can also use prop.table(table(data)) which is equivalent to the division method.

How to Calculate Relative Frequency in R© - All Rights Reserved 2025