Create a Tabular representation of Data in R Programming – table() Function

table() function in R Language is used to create a categorical representation of data with variable name and the frequency in the form of a table.

Syntax: table(x)

Parameters:
x: Object to be converted

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R Program to create 
# a tabular representation of data
  
# Creating a vector
vec = c(2, 4, 3, 1, 2, 3, 2, 1, 4, 2
  
# Calling table() Function
table(vec)

chevron_right


Output:

vec
1 2 3 4 
2 4 2 2 

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R Program to create 
# a tabular representation of data
  
# Creating a data frame 
df = data.frame(  
  "Name" = c("abc", "cde", "def"),  
  "Gender" = c("Male", "Female", "Male"
)  
    
# Calling table() function 
table(df) 

chevron_right


Output:

     Gender
Name  Female Male
  abc      0    1
  cde      1    0
  def      0    1
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.