Cumulative Frequency and Probability Table in R (original) (raw)

Last Updated : 6 Aug, 2025

Cumulative frequency and probability tables help summarize data distributions. They show how data values accumulate over time or categories and allow us to calculate probabilities from frequency distributions.

Functions Used

frequency_table <- table (vec)

**Parameter:

cumsum ( frequency_table)

**Parameter:

prop.table(frequency_table)

**Parameter:

**Example 1: We are creating a frequency table and a cumulative frequency table from a sample of categorical values.

set.seed(1) vec <- sample(c("Geeks", "CSE", "R", "Python"), 50, replace = TRUE) data <- table(vec) print("Frequency Table") print(data) print("Cumulative Frequency Table") cumfreq_data <- cumsum(data) print(cumfreq_data)

`

**Output:

frequency

Output

**Example 2: We are creating a probability table by dividing the frequency counts by the total number of observations in the sample.

set.seed(1) vec <- sample(c("Geeks", "CSE", "R", "Python"), 50, replace = TRUE) data <- table(vec) print("Frequency Table") print(data) print("Probability Table") prob_data <- data / 50 print(prob_data)

`

**Output:

table

Output

**Example 3: We are creating a data frame that combines frequency, cumulative frequency and probability values into one structured table.

set.seed(1) vec <- sample(c("Geeks", "CSE", "R", "Python"), 50, replace = TRUE) data <- table(vec) num_obsrv <- 50 prob_data <- data / num_obsrv cumfreq_data <- cumsum(data) data_frame <- data.frame(data, cumfreq_data, prob_data) colnames(data_frame) <- c("data", "frequency", "cumulative_frequency", "data", "probability") print(data_frame)

`

**Output:

frequency_table

Output

The output displays a data frame showing each category along with its frequency, cumulative frequency and probability.