← Back to R Course | Chapter 8: Data Manipulation | Lesson 6 of 7

table()

In this page:

  1. table()

table()

table(x) counts how many times each distinct value appears in a vector, producing a frequency table. It's the quickest way to summarize categorical data. Passing two vectors, table(x, y), produces a cross-tabulation counting combinations of both.

Note: table() is the fastest way to check the distribution of values in a categorical column before deeper analysis.

Example: table()

markup
colors <- c("red", "blue", "red", "green", "blue", "red")

print(table(colors))
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.