The Wayback Machine - https://web.archive.org/web/20240118164640/https://www.geeksforgeeks.org/absolute-and-relative-frequency-in-r-programming/
Open In App
Related Articles

Absolute and Relative Frequency in R Programming

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In statistics, frequency or absolute frequency indicates the number of occurrences of a data value or the number of times a data value occurs. These frequencies are often plotted on bar graphs or histograms to compare the data values. For example, to find out the number of kids, adults, and senior citizens in a particular area, to create a poll on some criteria, etc.
In R language, frequencies can be depicted as absolute frequency and relative frequency.

Absolute Frequency

Absolute frequency shows the number of times the value is repeated in the data vector.

Formula:

 f_1+f_2+f_3+\ldots+f_n=N

where,

 f_i is represented as absolute frequency of each value
N represents total number of data values

In R, frequency table of a data vector can be created using table() function.
Syntax:

table(x)

where,
x is data vector

Example:
Assume, “M” represents males and “F” represents females in the data vector below.




# Defining vector
x <- c("M", "M", "F", "M", "M", "M", "F", "F", "F", "M")
  
# Absolute frequency table
af <- table(x)
  
# Printing frequency table
print(af)
  
# Check the class
class(af)


Output:

x
F M 
4 6 
[1] "table"

Relative Frequency

Relative frequency is the absolute frequency of that event divided by the total number of events. It represents the proportion of a particular data category present in the data vector. Mathematically,

 n_i=\displaystyle \frac{f_i}{N}

where,

n_i represents the relative frequency of i^{\text{th}} event
f_i is represented as absolute frequency of each value
N represents total number of data values

In R language, table() function and length of data vector is used together to find relative frequency of data vector.
Syntax:

table(x)/length(x)

Example:




# Defining vector
x <- c("M", "M", "F", "M", "M", "M", "F", "F", "F", "M")
  
# Relative frequency table
rf <- table(x)/length(x)
  
# Printing frequency table
print(rf)
  
# Check the class
class(rf)


Output:

x
  F   M 
0.4 0.6
[1] "table"


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 04 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads