Absolute and Relative Frequency in R Programming
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
Formula:
where,
is represented as absolute frequency of each value N represents total number of data values
table()
Syntax:
table(x)
where,
x
Example:
# 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
where,
represents the relative frequency of event is represented as absolute frequency of each value N represents total number of data values
table()
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"
Contact Us