How to Create Tables in R? Last Updated : 27 Dec, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to create tables in R Programming Language. Method 1: Create a table from scratch We can create a table by using as.table() function, first we create a table using matrix and then assign it to this method to get the table format. Syntax: as.table(data) Example: In this example, we will create a matrix and assign it to a table in the R language. R # create matrix with 4 columns and 4 rows data= matrix(c(1:16), ncol=4, byrow=TRUE) # specify the column names and row names of matrix colnames(data) = c('col1','col2','col3','col4') rownames(data) <- c('row1','row2','row3','row4') # assign to table final=as.table(data) # display final Output: col1 col2 col3 col4 row1 1 2 3 4 row2 5 6 7 8 row3 9 10 11 12 row4 13 14 15 16Method 2: Create a table from an existing dataframe We can create from the existing dataframe using table() function Syntax: table(dataframe$column_name, dataframe$column_name) where, dataframe  is the input dataframecolumn_name is the column names to be created as tables from the dataframe Example: In this example, we will be creating a table from an existing data frame using the table function in the R language. R # create dataframe with 4 columns and 4 rows data= data.frame(col1=c(1:4),col2=c(5:8), col3=c(9:12),col4=c(13:16)) # assign to table from dataframe final=table(data$col1,data$col2) # display final Output: 5 6 7 8 1 1 0 0 0 2 0 1 0 0 3 0 0 1 0 4 0 0 0 1 Comment More infoAdvertise with us Next Article How to Create Tables in R? 171fa07058 Follow Improve Article Tags : R Language R DataFrame-Function R Matrix-Function Similar Reads How to Create Pivot Tables in R? In this article, we will discuss how to create the pivot table in the R Programming Language. The Pivot table is one of Microsoft Excel's most powerful features that let us extract the significance from a large and detailed data set. A Pivot Table often shows some statistical value about the dataset 2 min read How to Create Summary Tables in R? In this article, we will discuss how to create summary tables in R Programming Language. The summary table contains the following information: vars: represents the column numbern: represents the number of valid casesmean: represents the mean valuemedian: represents the median valuetrimmed: represent 4 min read How to Create a Two Way Table in R? In this article, we will create a two-way table in R programming language. A two-way table is used to display frequency for two categorical variables. The rows represent the categorical features and the column represents frequency. We can create two-way table using as.table() method. as.table() func 2 min read How to Create a Three Way Table in R A three-way table, also known as a three-dimensional contingency table, is a tabular representation of the joint frequencies of three categorical variables. It provides a way to analyze the relationships between three categorical variables simultaneously. In this article, we will study different app 6 min read How to Handle table Error in R R Programming Language is commonly used for data analysis, statistical modeling, and visualization. However, even experienced programmers make blunders while dealing with R code. Error management is critical for ensuring the reliability and correctness of data analysis operations. Common causes of t 2 min read Like