How to generate Frequency tables in R?

Description

To generate the frequency tables using R programming.

Table() :

   To generate frequency tables

   R Function :table()

ftable() :

  To print the results more attractively.

   R Function :ftable()

Margin :

   To generate marginal frequencies

   R Function :table()

Proportion table:

  To generate tables of proportions

   R Function :table()

Crosstable:

   R Package :gmodels

   To produce crosstabulations model

   R Function :CrossTable()

#Frequency and Contingency Tables
#Input
attach(mtcars)
x<-mtcars$mpg
y<-mtcars$hp

#Table Function
tab<-table(x,y)
print(tab)

#ftable
tab_f<-ftable(x,y)
print(tab_f)

#Marginal Frequencies
margin.table(tab,1)
margin.table(tab,2)

#table of Proportion
prop.table(tab_f,1)
prop.table(tab_f,2)

#Cross table Function
library(“gmodels”)

#Simple Input
x1<-c(2,4,2,6,2)
x2<-c(2,4,3,6,3)
CrossTable(x1,x2)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit