Calculating the Proportion of Factor Values in ‘R’

Suppose we have a table where one of the column has only two unique values e.g. Sex and we need to calculate the proportion (ratio) of each Sex. We can use the function prop.table to calculate and tabulate the results

# We have a data-frame Heights
data("heights")
# Save the values of Sex column of the data-frame in vector x
x <- heights$Sex
# Use the function Prop.Table on Vector x and Tabulate the output
prop.table(table(x))