How to Create a Frequency Table in R

· 2 min read · Updated March 15, 2026 · beginner
r frequency table dplyr data-table

A frequency table shows how many times each value appears in your data. This is useful for understanding the distribution of categorical variables.

With base R

The table() function creates frequency counts:

colors <- c("red", "blue", "red", "green", "blue", "red")
table(colors)
# colors
# blue green   red 
#    2     1     3 

Include NA values with useNA:

scores <- c(85, 92, NA, 78, NA, 88)
table(scores, useNA = "ifany")
# scores
#   78   85   88   92 <NA> 
#     1    1    1    1    2 

With dplyr

Use count() for a tibble output:

library(dplyr)

df <- data.frame(color = c("red", "blue", "red", "green", "blue", "red"))
df %>% count(color, sort = TRUE)
# # A tibble: 3 x 2
#   color     n
# 1 red       3
# 2 blue      2
# 3 green     1

With data.table

library(data.table)

dt <- data.table(color = c("red", "blue", "red", "green", "blue", "red"))
dt[, .N, by = color][order(-N)]
#    color N
# 1:   red 3
# 2:  blue 2
# 3: green 1

Proportions and Percentages

Convert counts to proportions:

tbl <- table(colors)
prop.table(tbl)
# colors
#   blue  green   red 
#  0.333  0.167   0.500 

# As percentages
100 * prop.table(tbl)
# colors
#   blue  green   red 
#  33.3  16.7    50.0 

See Also