Absolute and Relative Frequency in R Programming
Last Updated :
04 May, 2020
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:
where,
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.
x < - c( "M" , "M" , "F" , "M" , "M" , "M" , "F" , "F" , "F" , "M" )
af < - table(x)
print (af)
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,
where,
represents the relative frequency of event
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:
x < - c( "M" , "M" , "F" , "M" , "M" , "M" , "F" , "F" , "F" , "M" )
rf < - table(x) / length(x)
print (rf)
class (rf)
|
Output:
x
F M
0.4 0.6
[1] "table"
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...