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 16
How to Create Tables in R?
In this article, we will discuss how to create tables in R Programming Language.