The prop.table()
function in R creates table entries as fractions of a marginal table.
The prop.table()
function shows the individual value as a fraction of the whole. These fractions (the values in the table) sum up to 1
.
The prop.table()
function takes the syntax shown in the code widget below.
prop.table(x, margin=NULL)
The prop.table()
function takes the following parameter values:
x
: This is the R object that will serve as the table. This is a required parameter.margin
: This is an index or vector of indices for which the margin is generated. This is an optional parameter.The prop.table()
function returns a table expressed relative to the margin
.
# creating a matrix objectmy_matrix <- matrix (c( 1, 3, 1,7, 3, 5),ncol = 3,byrow = TRUE)# implementing the prop.table() functionprop.table(my_matrix)
my_matrix
using the matrix()
function.prop.table()
function, we return a table showing each value as a proportion of the whole value in the table. When these proportions are added, they equal 1
.