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

Nrepresents total number of data values

In R, frequency table of a data vector can be created using

function.**table()**

**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) ` |

*chevron_right*

*filter_none*

**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

Nrepresents total number of data values

In R language,

function and length of data vector is used together to find relative frequency of data vector.**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) ` |

*chevron_right*

*filter_none*

**Output:**

x F M 0.4 0.6 [1] "table"

## Recommended Posts:

- Calculate the absolute value in R programming - abs() method
- Compute the Natural Logarithm of the Absolute Value of Gamma Function in R Programming - lgamma() Function
- Calculate the Median Absolute Deviation in R Programming - mad() Function
- Count the Frequency of elements in a Numeric Vector - tabulate() Function
- Compute Variance and Standard Deviation of a value in R Programming - var() and sd() Function
- Calculate the Floor and Ceiling values in R Programming - floor() and ceiling() Function
- Naming Rows and Columns of a Matrix in R Programming - rownames() and colnames() Function
- Get Date and Time in different Formats in R Programming - date(), Sys.Date(), Sys.time() and Sys.timezone() Function
- Compute the Parallel Minima and Maxima between Vectors in R Programming - pmin() and pmax() Functions
- Add Leading Zeros to the Elements of a Vector in R Programming - Using paste0() and sprintf() Function
- Skewness and Kurtosis in R Programming
- Convert Factor to Numeric and Numeric to Factor in R Programming
- Grid and Lattice Packages in R Programming
- Logarithmic and Power Functions in R Programming
- Covariance and Correlation in R Programming
- Getting and Setting Length of the Vectors in R Programming - length() Function
- Accessing variables of a data frame in R Programming - attach() and detach() function
- Check if values in a vector are True or not in R Programming - all() and any() Function
- Return an Object with the specified name in R Programming - get0() and mget() Function
- Evaluating an Expression in R Programming - with() and within() Function

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.